Skip to content

Commit

Permalink
fix(cursor): optimization was wrong, can't use empty cursor for compl…
Browse files Browse the repository at this point in the history
…etion
  • Loading branch information
djMax committed Apr 1, 2024
1 parent 724ff53 commit 3d66c4e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/asDataGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export function asDataGenerator<T extends ResultWithCursor>(

return {
async *getGenerator(cursor: string | undefined) {
if (cursor === '') {
// The special empty string cursor indicates we should not fetch any more.
return;
}

let currentCursor = cursor;
let continueFetching = true;

Expand Down
6 changes: 1 addition & 5 deletions src/multiSourcePager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export async function multiSourcePager<Types extends Array<Source>>(
index,
key: dataSources[index].sortKey(item.value),
});
} else {
cursors[index] = '';
}
}));

Expand All @@ -65,9 +63,7 @@ export async function multiSourcePager<Types extends Array<Source>>(

// Fetch next item from the generator of the data source that the last item came from
const nextResult = await generators[index].next();
if (nextResult.done) {
cursors[index] = '';
} else {
if (!nextResult.done) {
queue.push({
result: nextResult.value,
index,
Expand Down
12 changes: 6 additions & 6 deletions src/queuePager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ describe('multi source pager', () => {
"type": "letter",
},
{
"cursor": "WyIiLCIyMDIzLTAxLTA2VDAwOjAwOjAwLjAwMFojRkYiXQ==",
"cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDZUMDA6MDA6MDAuMDAwWiNGRiJd",
"data": "FF",
"type": "letter",
},
{
"cursor": "WyIiLCIyMDIzLTAxLTA3VDAwOjAwOjAwLjAwMFojR0ciXQ==",
"cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDdUMDA6MDA6MDAuMDAwWiNHRyJd",
"data": "GG",
"type": "letter",
},
Expand All @@ -98,7 +98,7 @@ describe('multi source pager', () => {
expect(p4.results).toMatchInlineSnapshot(`
[
{
"cursor": "WyIiLCIyMDIzLTAxLTA4VDAwOjAwOjAwLjAwMFojSEgiXQ==",
"cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDhUMDA6MDA6MDAuMDAwWiNISCJd",
"data": "HH",
"type": "letter",
},
Expand Down Expand Up @@ -137,17 +137,17 @@ describe('multi source pager', () => {
"type": "letter",
},
{
"cursor": "WyIyMDIzLTAxLTAzVDAwOjAwOjAwLjAwMFojQyIsIiJd",
"cursor": "WyIyMDIzLTAxLTAzVDAwOjAwOjAwLjAwMFojQyIsIjIwMjMtMDEtMDJUMDA6MDA6MDAuMDAwWiNCQkIiXQ==",
"data": "C",
"type": "letter",
},
{
"cursor": "WyIyMDIzLTAxLTA0VDAwOjAwOjAwLjAwMFojRCIsIiJd",
"cursor": "WyIyMDIzLTAxLTA0VDAwOjAwOjAwLjAwMFojRCIsIjIwMjMtMDEtMDJUMDA6MDA6MDAuMDAwWiNCQkIiXQ==",
"data": "D",
"type": "letter",
},
{
"cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIiJd",
"cursor": "WyIyMDIzLTAxLTA1VDAwOjAwOjAwLjAwMFojRSIsIjIwMjMtMDEtMDJUMDA6MDA6MDAuMDAwWiNCQkIiXQ==",
"data": "E",
"type": "letter",
},
Expand Down

0 comments on commit 3d66c4e

Please sign in to comment.