我在promise中使用promise并调用外部函数来获取数据。外部函数使用回调来发回数据。有人可以帮助如何发送回应响应承诺?下面是我的代码
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 ) );
} );