如何await
使用with或withasync
调用函数?call
apply
Babel
下面是一个示例,其中getOrders
是类的async
方法Service
:
class Service() {
async getOrders(arg1, arg2, arg3) {
return await this.anotherService.getOrders(arg1, arg2, arg3);
}
}
let service = new Service();
// ...
// Babel doesn't compile
// let stream = await service.getOrders.call(this, arg1, arg2, arg3);
// producing SyntaxError: Unexpected token for await
let stream = service.getOrders.call(this, arg1, arg2, arg3);
stream.pipe(res); // obviously not working without await in the prev line