Skip to content

Commit

Permalink
feat(zip): Make it parallel as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpodwysocki committed Jul 25, 2017
1 parent b130e9c commit c505389
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/asynciterable/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class ZipIterable<TSource, TResult> extends AsyncIterableX<TResult> {
async *[Symbol.asyncIterator]() {
const it1 = this._left[Symbol.asyncIterator]();
const it2 = this._right[Symbol.asyncIterator]();
let next1, next2;
while (!(next1 = await it1.next()).done && (!(next2 = await it2.next()).done)) {
yield await this._fn(next1.value, next2.value);
while (1) {
const [next1, next2] = await Promise.all([it1.next(), it2.next()]);
if (!next1.done && !next2.done) {
yield await this._fn(next1.value, next2.value);
} else {
break;
}
}
}
}
Expand Down

0 comments on commit c505389

Please sign in to comment.