Skip to content

Commit 7c9b1c1

Browse files
authored
Explainer: Sync iterables now close when they yield rejected promises
See #49. No spec update is needed as per #49 (comment).
1 parent a64b19b commit 7c9b1c1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

README.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,12 @@ Array.fromAsync([], 1);
399399
### Closing sync iterables?
400400
Array.fromAsync tries to match `for await`’s behavior as much as possible.
401401
402-
This includes how `for await` currently does not close sync iterables when it
402+
Previously, `for await` did not close sync iterables when it
403403
yields a rejected promise.
404404
405+
<details>
406+
<summary>Old code example</summary>
407+
405408
```js
406409
function * createIter() {
407410
try {
@@ -433,13 +436,19 @@ for await (const x of createIter()) {
433436
Array.fromAsync(createIter());
434437
```
435438
436-
TC39 has agreed to change `for await`’s behavior here. In the future, `for await` will
437-
close sync iterators when async wrappers yield rejections (see [tc39/ecma262#2600][]).
438-
When that behavior changes for `for await`, then it will also change for `Array.fromAsync`
439-
at the same time.
439+
</details>
440+
441+
TC39 has recently changed `for await`’s behavior here.
442+
In the latest version of the language,
443+
`for await` now will close sync iterators when async wrappers yield rejections (see [tc39/ecma262#2600][]).
444+
All of the JavaScript engines are already updating to this new behavior.
440445
441446
[tc39/ecma262#2600]: https://github.com/tc39/ecma262/pull/2600
442447
448+
`Array.fromAsync` matches this new behavior of `for await`.
449+
Both will close any given sync iterator
450+
when the sync iterator yields a rejected promise as its next value.
451+
443452
## Other proposals
444453
445454
### Relationship with iterator-helpers

0 commit comments

Comments
 (0)