为什么要从 async/await 提案中删除 await*?
Why was await* removed from the async/await proposal?
它似乎被记录在案的唯一地方是 this issue thread and the actual specification。但是,删除的原因并没有在我能找到的任何地方发布。
新的推荐方式似乎是await Promise.all()
,但我很好奇为什么await*
被删除了。
好吧,自述文件的最后修订 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.
所以它并不像人们预期的那样直接类似于 yield*
,它 没有任何意义,这只是一个建议,但 从未真正包含在规范提案中。
共识是没有理由引入不必要的语法糖,调用Promise.all
没有太大区别。
您可以查看 issue 8 or issue 29 中的讨论。
最后,关于更强大武器(并行)的提议仍在进行中。查看 async iteration, async generators and observables。可能有一些可以使用 await*
关键字比简单的承诺数组好得多。
async
/await
提议是最小化的,只介绍了必要的原语。没有关于可能扩展的 bikeshedding,应该单独讨论。
它似乎被记录在案的唯一地方是 this issue thread and the actual specification。但是,删除的原因并没有在我能找到的任何地方发布。
新的推荐方式似乎是await Promise.all()
,但我很好奇为什么await*
被删除了。
好吧,自述文件的最后修订 before it was removed 已经提到了该段中的所有内容:
await* and parallelism
In generators, both
yield
andyield*
can be used. In async functions, onlyawait
is allowed. The direct analogoue ofyield*
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 (foryield*
, 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.
所以它并不像人们预期的那样直接类似于 yield*
,它 没有任何意义,这只是一个建议,但 从未真正包含在规范提案中。
共识是没有理由引入不必要的语法糖,调用Promise.all
没有太大区别。
您可以查看 issue 8 or issue 29 中的讨论。
最后,关于更强大武器(并行)的提议仍在进行中。查看 async iteration, async generators and observables。可能有一些可以使用 await*
关键字比简单的承诺数组好得多。
async
/await
提议是最小化的,只介绍了必要的原语。没有关于可能扩展的 bikeshedding,应该单独讨论。