kinetex - v1.0.0-rc.1
    Preparing search index...

    Class BatchQueue<T>

    Batch request queue — coalesces individual requests fired within the same micro-task tick (or within flushMs) into a concurrent Promise.all burst, sharing a single connection pool flush.

    This is a high-throughput helper for write-heavy scenarios (e.g. event ingestion, metric flushing) where you want to fire many requests quickly without overloading the event loop one-by-one.

    const batch = new BatchQueue(client, { maxBatch: 50, flushMs: 10 });

    // Fire individual requests — they batch automatically
    const [r1, r2, r3] = await Promise.all([
    batch.enqueue("/events", "POST", { body: JSON.stringify(event1) }),
    batch.enqueue("/events", "POST", { body: JSON.stringify(event2) }),
    batch.enqueue("/events", "POST", { body: JSON.stringify(event3) }),
    ]);

    Enterprise Hardening #4 — Request batching for high-throughput scenarios

    Type Parameters

    • T = unknown
    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Type Parameters

      • T = unknown

      Parameters

      • client: Kinetex

        The Kinetex client to send requests through.

      • options: { maxBatch?: number; flushMs?: number } = {}

        Batch configuration options.

        • OptionalmaxBatch?: number

          Maximum number of requests to flush at once. When this many requests are queued, flush immediately. Default: 100

        • OptionalflushMs?: number

          Milliseconds to wait before flushing an incomplete batch. Allows requests fired in the same event-loop tick to coalesce. Default: 0 (flush on next microtask)

      Returns BatchQueue<T>

    Accessors

    • get pendingCount(): number

      How many requests are currently queued (not yet sent).

      Returns number

    Methods

    • Enqueue a request. Returns a promise that resolves when the batch containing this request has been sent and the response is ready.

      Parameters

      • url: string

        Request URL.

      • method: HTTPMethod = "GET"

        HTTP method (default GET).

      • options: SendOptions<T> = {}

        Per-request options.

      Returns Promise<KinetexResponse<T>>

      A promise resolving with the response.

    • Flush any pending requests immediately without waiting for the timer. Loops until the queue is empty so items beyond maxBatch are not orphaned.

      Returns void