I'm using promise inside a promise and calling external functions to get data. The external functions using a callback to send the data back. Could someone please help how to send callback response to promise? below is my code
function processData( data ){
....
}
function getData( data ) {
const callbacks = {
error(e) {
console.log('error',e)
}
dataReady(data){
// I want this data to be sent back to my original promise, while which use in processData function
return data
}
}
const obj = api.init( args, callbacks);
// TODO: 1) How can I wait this function to complete the callbacks
2) How can I capture callbacks response
}
new Promise( ( res, rej ) => {
const req = new Request( args );
req.send()
.then( getData )
.then( processData )
.then( ( data ) => res( data ) )
.catch( ( err ) => rej( err ) );
} );