Ability to abort asynchronous call

后端 未结 3 1640
天命终不由人
天命终不由人 2020-12-31 08:24

I\'m using babeljs with es7 style async/await methods. I have a main script that will call a async method on an array of objects that all return promises. I use Promise.al

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 09:04

    If you can migrate to Typescript (in which types are optional and es6 and some es7 features are supported out of the box) instead of Babel and use Bluebird promises, the kind of cancellation semantics you are looking for can be achieved.

    I've created a simple module which replaces the default Typescript __awaiter helper with one that supports Bluebird cancellations: https://www.npmjs.com/package/cancelable-awaiter

    With it you can use aync/await syntax in conjunction with promise.cancel() and promise.finally() which Bluebird gives you.

提交回复
热议问题