Skip to content

Commit 101390c

Browse files
committed
perf(asyncEqualOnce): iterate both iterators simultaneously
1 parent 4833d14 commit 101390c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,13 @@ export async function asyncEqualOnce<T>(
429429
): Promise<boolean> {
430430
const ait = asyncIterator(a);
431431
const bit = asyncIterator(b);
432-
let aElement = await ait.next();
433-
let bElement = await bit.next();
432+
let [aElement, bElement] = await Promise.all([ait.next(), bit.next()] as const);
434433
while (
435434
aElement.done !== true &&
436435
bElement.done !== true &&
437436
(await elementsEqual(aElement.value, bElement.value))
438437
) {
439-
aElement = await ait.next();
440-
bElement = await bit.next();
438+
[aElement, bElement] = await Promise.all([ait.next(), bit.next()] as const);
441439
}
442440
return aElement.done === true && bElement.done === true;
443441
}

0 commit comments

Comments
 (0)