AniLink - v3.1.0
    Preparing search index...

    Function fetchWithLookAhead

    • Shared look-ahead driver for paged traversals.

      Fetches entries through a sliding window of at most concurrency launched- but-unconsumed requests so round-trip latency overlaps instead of stacking, while results are appended strictly in entry order no matter when each request settles. Scheduling stops as soon as an entry reports "no more data" (per the caller-supplied extractHasMore), at the maxEntries guard, or, when extractBound is supplied, at the smallest launch bound a received entry reported; truncated mirrors the sequential semantics.

      Because the window runs ahead of consumption, up to concurrency - 1 already-launched requests may complete past a terminal entry; their payloads are drained and discarded so the collected prefix matches what a strictly sequential traversal would have returned.

      When the optional signal is aborted, any in-flight requests are settled (their payloads discarded) and the entries collected so far are returned as a partial result with truncated: false. The abort is not propagated as a rejection.

      Type Parameters

      • TEntry

        The raw response shape of a single page or chunk.

      Parameters

      • fetch: (key: number) => Promise<TEntry>

        Callback that fetches a single entry given its numeric page key.

      • extractHasMore: (response: TEntry) => boolean

        Reads the "more data available" flag from a fetched entry. Return false for malformed responses so a broken payload ends the traversal instead of looping forever.

      • startNumber: number

        The 1-based page number to start from.

      • maxEntries: number

        Hard cap on entries fetched, guarding against unbounded loops.

      • concurrency: number

        Maximum number of requests kept in flight at once.

      • Optionalsignal: AbortSignal

        Optional AbortSignal to cancel the traversal.

      • OptionalextractBound: (response: TEntry) => number | undefined

        Optional reader for the terminal page bound a fetched entry reports (AniList's pageInfo.lastPage). Supply it only when entry numbers are page numbers; chunk-style traversals omit it so their scheduling is governed solely by the terminal entry and guard checks.

      Returns Promise<LookAheadResult<TEntry>>

      The responses in entry order, how many were fetched, and whether the guard or a reported launch bound truncated the run.

      The rejection from the next unconsumed fetch call in entry order, unless the signal aborted (in which case a partial result is returned).