【发布时间】:2019-07-12 15:04:02
【问题描述】:
我正在使用 async/await 返回 Promise ,将其用作节点脚本中的 promoise。当我尝试将返回值用作 Promise 时,它会给出错误 a.then is not a function
这里是示例代码
function test () {
//do something .......
//....
return global.Promise;
}
(async ()=> {
let a = await test();
a.then(()=> { console.log('good ')}, (err)=> { console.log()});
})();
【问题讨论】:
-
您可以使用
return Promise.resolve( );,但您还需要删除await以使a成为promise。
标签: javascript node.js promise async-await es6-promise