nuxt
Version:
49 lines • 2.29 kB
TypeScript
//#region src/app/internal/prefetch.d.ts
/** drained in this order */
declare const PREFETCH_PRIORITIES: readonly ["route", "payload", "island", "hint"];
export type PrefetchPriority = typeof PREFETCH_PRIORITIES[number];
export interface PrefetchTask {
/** A task whose key is already queued or in flight is dropped. */
key: string;
priority: PrefetchPriority;
/** `navigation` tasks are aborted and dequeued when the app navigates. */
scope: 'navigation' | 'app';
/** The destination this work belongs to. Promoted together, and retained across a navigation to it. */
group?: string;
/**
* Runs exactly once, so that callers can rely on its result settling. A dropped task (a
* duplicate key, or dequeued by a navigation) is run with an aborted signal rather than
* given a slot.
*/
run: (signal: AbortSignal, promoted: boolean) => unknown | Promise<unknown>;
}
interface PrefetchSchedulerOptions {
total?: number;
/** Per-priority caps keep one kind of work, such as slow resource hints, off the whole budget. */
concurrency?: Partial<Record<PrefetchPriority, number>>;
/** Consulted before each drain; queued tasks are held, not dropped, when it returns `false`. */
canPrefetch?: () => boolean;
/** Hands a started task to the event loop. Slots are accounted for before this is called. */
defer?: (run: () => void, promoted: boolean, priority: PrefetchPriority) => void;
}
export interface PrefetchScheduler {
/** A batch is queued ahead of work already queued at the same priority, keeping its own order. */
schedule: (task: PrefetchTask | PrefetchTask[]) => void;
/** Move every queued task in this group to the front of its priority. */
promote: (group: string) => void;
/**
* Abort in-flight `navigation` tasks and drop queued ones, except work for `retainGroup`.
* Its forwarded hints go too, as a destination re-declares those itself once it is current.
*/
reset: (retainGroup?: string) => void;
/** Drain again, once something that was holding work back has changed. */
resume: () => void;
/** @internal */
inspect?: () => {
active: number;
pending: string[];
};
}
export declare function createPrefetchScheduler(options?: PrefetchSchedulerOptions): PrefetchScheduler;
//#endregion
export {};