From 993faa672d16440d335d056abd4a2d3af27d55be Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 19 Aug 2022 18:02:40 +0300 Subject: [PATCH] added for-await-of support for Promise.iter(..)... Signed-off-by: Alex A. Naanou --- Promise.js | 9 +++++++++ README.md | 8 ++++++++ package.json | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Promise.js b/Promise.js index 215f51b..7614003 100644 --- a/Promise.js +++ b/Promise.js @@ -249,6 +249,15 @@ object.Constructor('IterablePromise', Promise, { : (await Promise.all(list)) .flat() }, + [Symbol.asyncIterator]: async function*(){ + var list = this.__packed + if(list instanceof Promise){ + yield this.__unpack(await list) + return } + for await(var elem of list){ + yield* elem instanceof Array ? + elem + : [elem] } }, // iterator methods... // diff --git a/README.md b/README.md index 517c5e8..dcf83a6 100644 --- a/README.md +++ b/README.md @@ -1580,6 +1580,14 @@ in how they process values: appropriate method on the result. +Promise iterators directly support _for-await-of_ iteration: + +```javascript +for await (var elem of Promise.iter(/* ... */)){ + // ... +} +``` +