Skip to content

Commit

Permalink
a.toSorted(f) -> structuredClone(a).sort(f) (former not avalailable i…
Browse files Browse the repository at this point in the history
…n node18)
  • Loading branch information
tgfisher4 committed Aug 25, 2024
1 parent 5a8bb4c commit 6cac3dc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,9 @@ test('pMapIterable - preserveOrder: false - more complex example - async iterabl
yield * testData;
}

t.deepEqual(await collectAsyncIterable(pMapIterable(asyncIterable(), mapper, {concurrency: Number.POSITIVE_INFINITY, preserveOrder: false})), testData.toSorted(([_aId, aMs], [_bId, bMs]) => aMs - bMs).map(([id, _ms]) => id));
const sortedTestData = structuredClone(testData).sort(([_aId, aMs], [_bId, bMs]) => aMs - bMs);

t.deepEqual(await collectAsyncIterable(pMapIterable(asyncIterable(), mapper, {concurrency: Number.POSITIVE_INFINITY, preserveOrder: false})), sortedTestData.map(([id, _ms]) => id));
});

test('pMapIterable - preserveOrder: false - more complex example - sync promise-returning iterable and unbounded concurrency', async t => {
Expand All @@ -855,7 +857,9 @@ test('pMapIterable - preserveOrder: false - more complex example - sync promise-
yield * testData.map(d => Promise.resolve(d));
}

t.deepEqual(await collectAsyncIterable(pMapIterable(syncPromiseReturningIterable(), mapper, {concurrency: Number.POSITIVE_INFINITY, preserveOrder: false})), testData.toSorted(([_aId, aMs], [_bId, bMs]) => aMs - bMs).map(([id, _ms]) => id));
const sortedTestData = structuredClone(testData).sort(([_aId, aMs], [_bId, bMs]) => aMs - bMs);

t.deepEqual(await collectAsyncIterable(pMapIterable(syncPromiseReturningIterable(), mapper, {concurrency: Number.POSITIVE_INFINITY, preserveOrder: false})), sortedTestData.map(([id, _ms]) => id));
});

test('pMapIterable - preserveOrder: false - concurrency: 2', async t => {
Expand Down

0 comments on commit 6cac3dc

Please sign in to comment.