/** * The ServiceWorker's table of handler links, per key. Pure bookkeeping, no * ports, so routing can be tested without a browser. */ /** What a `route` function sees of a handler. */ export interface HandlerInfo { /** The handler slot, unique within its key. */ readonly id: string; readonly key: string; /** Token of the current attachment; `drain` and `detach` must name it. */ readonly owner: string; /** Requests sent to it whose responses have not finished. */ readonly inflight: number; /** Whatever the attaching page sent. */ readonly meta: unknown; /** When it attached (`Date.now()`); ties go to the oldest. */ readonly attachedAt: number; /** Draining: it finishes what it has and gets nothing new. */ readonly draining: boolean; } /** * Picks the handler for one request among the live (not draining) handlers of * its key. `undefined` means none of them: the request waits for another, as * when there is none at all. */ export type RouteFunction = (request: Request, key: string, handlers: H[]) => H | undefined; /** * The default route: the handler with the fewest requests in flight, the * oldest on a tie. With one handler per key — one tab — that is the first * live handler of the key, as before routing was pluggable. */ export declare const leastInflightRoute: RouteFunction; export declare class HandlerTable { private readonly _entries; private _waiters; /** Adds `entry`. Returns the entry it replaces (same key and id), if any. */ add(entry: E): E | undefined; /** Removes `entry` if it is still the one in its slot. */ remove(entry: E): boolean; get(key: string, id: string): E | undefined; /** Every entry of `key`, draining or not. */ all(key: string): E[]; /** The entries of `key` that take new requests. */ live(key: string): E[]; entries(): E[]; get size(): number; /** * Resolves `true` once a live entry for `key` is added (at once if there is * one, unless `next`), `false` after `ms`. */ waitFor(key: string, ms: number, next?: boolean): Promise; } //# sourceMappingURL=handler-table.d.ts.map