Skip to content

Commit

Permalink
Provide access to whether we are sync iterating or not
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jan 31, 2024
1 parent 7e7d584 commit 4fab6c6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions util/RangeIterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class RangeIterable {
let iterable = new RangeIterable();
iterable.iterate = (async) => {
let iterator = source[async ? Symbol.asyncIterator : Symbol.iterator]();
if (!async) source.isSync = true;
let i = 0;
return {
next(resolvedResult) {
Expand Down Expand Up @@ -45,11 +46,9 @@ export class RangeIterable {
if (iterable.onDone) iterable.onDone();
return iteratorResult;
}
result = func(iteratorResult.value, i++);
if (result && result.then) {
if (!async) {
throw new Error('Can not synchronously iterate with asynchronous values');
}
result = func.call(source, iteratorResult.value, i++);
if (result && result.then && async) {
// if async, wait for promise to resolve before returning iterator result
return result.then(result =>
result === SKIP ?
this.next() :
Expand Down

0 comments on commit 4fab6c6

Please sign in to comment.