@backblaze-labs/b2-sdk - v0.1.0
    Preparing search index...

    Function paginateItems

    • Async-iterates items by flattening pages. The extractItems function pulls the relevant array out of each page (e.g. page.files, page.keys, page.parts). Each item is yielded individually so the caller can for await (const item of paginator) rather than nest loops.

      Aborts between pages, not between items: if signal is aborted while the caller is processing the items of page N, the iterator will still yield all of page N's remaining items before checking the signal before fetching page N+1.

      Type Parameters

      • Page

        The per-page response shape.

      • Cursor

        The cursor type used to request the next page.

      • Item

        The item type the caller wants to iterate.

      Parameters

      • fetcher: PageFetcher<Page, Cursor>

        Function that fetches one page given the current cursor.

      • extractItems: (page: Page) => Iterable<Item>

        Pulls the iterable items out of a page.

      • signal: AbortSignal | undefined

        Optional abort signal. Checked before each fetch.

      Returns AsyncIterableIterator<Item>

      An async iterable of individual items.

      DOMException When signal is aborted between fetches.