@jiminp/tooltool
    Preparing search index...

    Function forEachPage

    • Fetches multiple pages in parallel and invokes a callback for each non-nullish page.

      Type Parameters

      • Page

        The page data type.

      Parameters

      • fetcher: PageFetcher<Page>

        Fetches a page by zero-based index.

      • callback: (page: NonNullable<Page>, index: number) => void

        Called for each non-nullish page (may be out-of-order).

      Returns Promise<void>

      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.