The page data type.
Fetches a page by zero-based index.
Called for each non-nullish page (may be out-of-order).
Resolves when all fetches and synchronous page callbacks finish.
Page 0 is fetched first to discover the count, even for an empty result.
All discovered remaining pages are then fetched in parallel with no
concurrency limit; consider using rateLimited to wrap the fetcher.
Higher reported counts schedule additional pages; lower counts do not cancel
already scheduled pages. Callbacks are synchronous and are not awaited.
Propagates fetch failures and synchronous callback exceptions. In-flight fetches continue after failure, but their pages and reported counts are ignored.
await forEachPage(
async (i) => ({ num_pages: 5, page: await fetchUsers(i) }),
(users, i) => console.log(`Page ${i}:`, users),
);
fetchPages for an async generator alternative.
Fetches multiple pages in parallel and invokes a callback for each non-nullish page.