Skip to content

Commit

Permalink
fix: next method for async
Browse files Browse the repository at this point in the history
  • Loading branch information
TanyaLagodich committed Sep 1, 2024
1 parent 20528b4 commit 8049aca
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/core/Iter8or.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class Iter8or {

next() {
if (!this.iterator) {
this.iterator = this[Symbol.iterator]();
this.iterator = this.options.async ? this[Symbol.asyncIterator]() : this[Symbol.iterator]();
}
return this.iterator.next();
}
Expand Down Expand Up @@ -183,3 +183,24 @@ export default class Iter8or {
return toString(this.iterable);
}
}

function fetchApiData1() {
return new Promise((resolve) => {
setTimeout(() => {
resolve([1, 2, 3, 4, 5]);
}, 1000);
});
}

function fetchApiData2() {
return new Promise((resolve) => {
setTimeout(() => {
resolve([6, 7, 8, 9, 10]);
}, 1500);
});
}

const iter = new Iter8or([fetchApiData1, fetchApiData2], { async: true });


console.log(await iter.next());

0 comments on commit 8049aca

Please sign in to comment.