The only place it seems to be documented is this issue thread and the actual specification. However, the reasoning for the removal isn't posted anywhere I could find.
The new recommended way seems to be await Promise.all()
, but I'm curious as to why await*
was removed.
Use of async and await enables the use of ordinary try / catch blocks around asynchronous code. Note: The await keyword is only valid inside async functions within regular JavaScript code. If you use it outside of an async function's body, you will get a SyntaxError .
The await operator doesn't block the thread that evaluates the async method. When the await operator suspends the enclosing async method, the control returns to the caller of the method.
We recommend using async/await where possible, and minimize promise chaining. Async/await makes JavaScript code more accessible to developers that aren't as familiar with JavaScript, and much easier to read.
If the promise is rejected, the await expression throws the rejected value. The function containing the await expression will appear in the stack trace of the error. Otherwise, if the rejected promise is not awaited or is immediately returned, the caller function will not appear in the stack trace.
Well, the last revision of the readme before it was removed already mentions everything in that paragraph:
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.
So it's no direct analogue to yield*
as one might expect, it doesn't really make sense, it was only a suggestion but never really included in the spec proposal.
The consensus was that there is no reason to introduce more syntactical sugar than necessary, calling Promise.all
is not much of a difference.
You can check out the discussions in issue 8 or issue 29.
Finally, proposals for mightier weapons (parallelism) are still under way. Check out async iteration, async generators and observables. There might be some that could use an await*
keyword much better than for simple arrays of promises.
The async
/await
proposal is minimal and only introduces the necessary primitives. There is no bikeshedding about possible extensions, which should be discussed separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With