Skip to content

Commit 4c0cbc1

Browse files
committed
PIK-10232 re-added comments
1 parent 9d42f5b commit 4c0cbc1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

v2/api-validator/tests/utils/pagination.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export type Pageable<T> = (limit: number, startingAfter?: string) => Promise<T[]
88
* one by one while automagically managing the pagination behind the scene.
99
*/
1010
export async function* paginated<T>(f: Pageable<T>, idPropName = 'id'): AsyncGenerator<T> {
11-
const MAX_PAGES = 20;
11+
const MAX_PAGES = 1000;
1212
let pageCount = 0;
13-
let cursor: string | undefined;
13+
let startingAfter: string | undefined;
1414

1515
while (pageCount < MAX_PAGES) {
16-
const currentPage = await f(LIMIT, cursor);
16+
const currentPage = await f(LIMIT, startingAfter);
1717

1818
if (currentPage.length === 0) {
1919
break;
@@ -26,13 +26,13 @@ export async function* paginated<T>(f: Pageable<T>, idPropName = 'id'): AsyncGen
2626
}
2727

2828
const lastItem = currentPage[currentPage.length - 1];
29-
const nextCursor = lastItem?.[idPropName];
29+
const lastItemId = lastItem?.[idPropName];
3030

31-
if (!nextCursor || nextCursor === cursor) {
31+
if (!lastItemId || lastItemId === startingAfter) {
3232
break;
3333
}
3434

35-
cursor = nextCursor;
35+
startingAfter = lastItemId;
3636
}
3737
}
3838

0 commit comments

Comments
 (0)