javascript – 为什么等待*从async / await提案中删除?

它似乎记录的唯一地方是this issue threadthe actual specification.但是,删除的原因并没有张贴在我能找到的任何地方.

新的推荐方式似乎是等待Promise.all(),但我很好奇为什么等待*被删除.

好了,自述文件before it was removed的最新版本已经提到了该段落中的所有内容:

await* and parallelism

In generators, both yield and yield* can be used. In async
functions, only await is allowed. The direct analogoue of yield*
does not make sense in async functions because it would need to
repeatedly await the inner operation, but does not know what value to
pass into each await (for yield*, it just passes in undefined
because iterators do not accept incoming values).

It has been suggested that the syntax could be reused for different
semantics – sugar for Promise.all. This would accept a value that is
an array of Promises, and would (asynchronously) return an array of
values returned by the promises. This is expected to be one of the
most common Promise-related oprerations that would not yet have syntax
sugar after the core of this proposal is available.

所以它并不像人们所期望的那样直接模拟*,它实际上没有意义,它只是一个建议,但从未真正包含在规范提案中.

一致认为,没有理由引入比必要更多的语法糖,称为Promise.all并没有多大区别.

您可以查看issue 8issue 29中的讨论.

最后,关于更强大武器(并行性)的建议仍在进行中.查看async iteration,async generatorsobservables.可能有一些可以使用await *关键字比简单的promises数组更好.

async / await提议是最小的,只引入必要的原语.关于可能的扩展没有自行决定,应该单独讨论.

翻译自:https://stackoverflow.com/questions/35168086/why-was-await-removed-from-the-async-await-proposal

转载注明原文:javascript – 为什么等待*从async / await提案中删除?