async await callback is not a function
This question already has an answer here:
Basically, you have to check if it returns promise - you can use it out of box. If not - you can promisify function you need. Something like this in result:
function saveModel(transaction) {
return new Promise ((resolve, reject) => {
transaction.save(err => {
if (err)
reject(err);
else
resolve();
});
});
}
Such function can be used with async/await:
async create(){
let transaction = new Transaction({name:'Couch'});
try{
await saveModel(transaction);
} catch (err) {
console.log(err);
}
}
Another option is to view source files, but I'm too lazy to do it.
链接地址: http://www.djcxy.com/p/55534.html上一篇: Javascript,如何等待多重承诺
下一篇: 异步等待回调不是一个函数