@@ -396,6 +396,50 @@ Array.fromAsync(null);
396
396
Array .fromAsync ([], 1 );
397
397
` ` `
398
398
399
+ ### Closing sync iterables?
400
+ Array.fromAsync tries to match ` for await ` ’s behavior as much as possible.
401
+
402
+ This includes how ` for await ` currently does not close sync iterables when it
403
+ yields a rejected promise.
404
+
405
+ ` ` ` js
406
+ function * createIter () {
407
+ try {
408
+ yield Promise .resolve (console .log (" a" ));
409
+ yield Promise .reject (" x" );
410
+ } finally {
411
+ console .log (" finalized" );
412
+ }
413
+ }
414
+
415
+ // Prints "a" and then prints "finalized".
416
+ // There is an uncaught "x" rejection.
417
+ for (const x of createIter ()) {
418
+ console .log (await x);
419
+ }
420
+
421
+ // Prints "a" and then prints "finalized".
422
+ // There is an uncaught "x" rejection.
423
+ Array .from (createIter ());
424
+
425
+ // Prints "a" and does *not* print "finalized".
426
+ // There is an uncaught "x" rejection.
427
+ for await (const x of createIter ()) {
428
+ console .log (x);
429
+ }
430
+
431
+ // Prints "a" and does *not* print "finalized".
432
+ // There is an uncaught "x" rejection.
433
+ Array .fromAsync (createIter ());
434
+ ` ` `
435
+
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.
440
+
441
+ [tc39/ecma262#2600]: https://github.com/tc39/ecma262/pull/2600
442
+
399
443
## Other proposals
400
444
401
445
### Relationship with iterator-helpers
0 commit comments