OzW*_*OzW 6 global node.js promise async-await bluebird
在Node.js v7.8.0中我有一个模块foo.js:
class Foo {
async bar() { return 'bar' }
}
Run Code Online (Sandbox Code Playgroud)
在主模块中,app.js我将Bluebird分配给全局Promise:
global.Promise = require('bluebird').
在'app.js'我有:
const Foo = require('./foo);
let foo = new Foo();
foo.bar().tap(res => console.log(res));
Run Code Online (Sandbox Code Playgroud)
我假设因为我用Bluebird替换了全局Promise,对异步函数的调用将返回一个Bluebird的承诺(有.tap),但显然我错了,因为我收到了错误:
TypeError: foo.bar(...).tap is not a function
有没有办法实现我的愿望?
| 归档时间: |
|
| 查看次数: |
280 次 |
| 最近记录: |