Is there a way to short circuit async/await flow?

前端 未结 7 2047
名媛妹妹
名媛妹妹 2020-12-02 11:19
async function update() {
   var urls = await getCdnUrls();
   var metadata = await fetchMetaData(urls);
   var content = await fetchContent(metadata);
   await rend         


        
相关标签:
7条回答
  • 2020-12-02 11:56

    You can get what you want using Typescript + Bluebird + cancelable-awaiter.

    Now that all evidence point to cancellation tokens not making it to ECMAScript, I think the best solution for cancellations is the bluebird implementation mentioned by @BenjaminGruenbaum, however, I find the usage of co-routines and generators a bit clumsy and uneasy on the eyes.

    Since I'm using Typescript, which now support async/await syntax for es5 and es3 targets, I've created a simple module which replaces the default __awaiter helper with one that supports bluebird cancellations: https://www.npmjs.com/package/cancelable-awaiter

    0 讨论(0)
提交回复
热议问题