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(/* ... */)){ + // ... +} +``` +