react-inp-chunker 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +141 -53
  2. package/core/package.json +10 -0
  3. package/dist/core/index.cjs +1 -1
  4. package/dist/core/index.d.cts +2 -2
  5. package/dist/core/index.d.ts +2 -2
  6. package/dist/core/index.js +1 -1
  7. package/dist/deferred-task-CwjZA3K-.js +713 -0
  8. package/dist/deferred-task-CwjZA3K-.js.map +1 -0
  9. package/dist/deferred-task-EWH55ZyL.cjs +796 -0
  10. package/dist/deferred-task-EWH55ZyL.cjs.map +1 -0
  11. package/dist/{index-C6B_Nm3i.d.ts → index-DShDP2VN.d.cts} +51 -6
  12. package/dist/index-DShDP2VN.d.cts.map +1 -0
  13. package/dist/{index-C6B_Nm3i.d.cts → index-DShDP2VN.d.ts} +51 -6
  14. package/dist/index-DShDP2VN.d.ts.map +1 -0
  15. package/dist/index.cjs +47 -12
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +20 -1
  18. package/dist/index.d.cts.map +1 -1
  19. package/dist/index.d.ts +20 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +24 -10
  22. package/dist/index.js.map +1 -1
  23. package/dist/production/core/index.cjs +16 -0
  24. package/dist/production/core/index.js +1 -0
  25. package/dist/{deferred-task-5kfztF2G.js → production/deferred-task-BGsfee-L.js} +177 -86
  26. package/dist/production/deferred-task-BGsfee-L.js.map +1 -0
  27. package/dist/{deferred-task-BXVzapQg.cjs → production/deferred-task-zVnq18IN.cjs} +177 -86
  28. package/dist/production/deferred-task-zVnq18IN.cjs.map +1 -0
  29. package/dist/production/index.cjs +195 -0
  30. package/dist/production/index.cjs.map +1 -0
  31. package/dist/production/index.js +172 -0
  32. package/dist/production/index.js.map +1 -0
  33. package/package.json +65 -22
  34. package/dist/deferred-task-5kfztF2G.js.map +0 -1
  35. package/dist/deferred-task-BXVzapQg.cjs.map +0 -1
  36. package/dist/index-C6B_Nm3i.d.cts.map +0 -1
  37. package/dist/index-C6B_Nm3i.d.ts.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"deferred-task-5kfztF2G.js","names":["normalizeTimeSliceMs"],"sources":["../src/core/chunk-machine.ts","../src/core/scheduler.ts","../src/core/chunk-scheduler.ts","../src/core/deferred-task.ts"],"sourcesContent":["/**\n * The state machine a chunk task moves through. Deliberately separate from\n * `chunk-scheduler.ts`'s async orchestration: this file is pure, synchronous,\n * and has nothing to fake-timer around, which is what makes it possible to\n * exhaustively test every (state, event) pair — all of them, not a sample.\n *\n * START CANCEL\n * idle ---------> processing ----------------> cancelled\n * | ^ ^ ^\n * PAUSE | | RESUME CANCEL| | CANCEL\n * v | | |\n * paused -+-------------------+ |\n * | |\n * COMPLETE | ERROR |\n * v |\n * done / error (terminal, absorb everything)\n *\n * `done`, `cancelled` and `error` are terminal: once reached, every further\n * event is a no-op that returns the same state object (referentially equal,\n * so a React reducer built on this never re-renders for a dead task). A\n * scheduler is one-shot by design — to run another task, create another\n * scheduler. That one rule is what keeps this table small enough to verify\n * completely instead of \"pretty thoroughly\".\n */\n\nexport type ChunkStatus =\n 'idle' | 'processing' | 'paused' | 'done' | 'cancelled' | 'error';\n\nexport type ChunkEvent =\n | { readonly type: 'START' }\n | { readonly type: 'PAUSE' }\n | { readonly type: 'RESUME' }\n | { readonly type: 'CANCEL' }\n | { readonly type: 'COMPLETE' }\n | { readonly type: 'ERROR'; readonly error: unknown };\n\nexport interface ChunkMachineState {\n readonly status: ChunkStatus;\n readonly error?: unknown;\n}\n\nexport const initialChunkState: ChunkMachineState = { status: 'idle' };\n\nexport type TerminalChunkStatus = 'done' | 'cancelled' | 'error';\n\nconst TERMINAL_STATUSES: ReadonlySet<ChunkStatus> = new Set<ChunkStatus>([\n 'done',\n 'cancelled',\n 'error',\n]);\n\nexport function isTerminal(status: ChunkStatus): status is TerminalChunkStatus {\n return TERMINAL_STATUSES.has(status);\n}\n\nfunction transitionIdle(state: ChunkMachineState, event: ChunkEvent): ChunkMachineState {\n switch (event.type) {\n case 'START':\n return { status: 'processing' };\n case 'CANCEL':\n return { status: 'cancelled' };\n case 'PAUSE':\n case 'RESUME':\n case 'COMPLETE':\n case 'ERROR':\n return state;\n }\n}\n\nfunction transitionProcessing(\n state: ChunkMachineState,\n event: ChunkEvent,\n): ChunkMachineState {\n switch (event.type) {\n case 'PAUSE':\n return { status: 'paused' };\n case 'CANCEL':\n return { status: 'cancelled' };\n case 'COMPLETE':\n return { status: 'done' };\n case 'ERROR':\n return { status: 'error', error: event.error };\n case 'START':\n case 'RESUME':\n return state;\n }\n}\n\nfunction transitionPaused(\n state: ChunkMachineState,\n event: ChunkEvent,\n): ChunkMachineState {\n switch (event.type) {\n case 'RESUME':\n return { status: 'processing' };\n case 'CANCEL':\n return { status: 'cancelled' };\n case 'START':\n case 'PAUSE':\n case 'COMPLETE':\n case 'ERROR':\n return state;\n }\n}\n\n/**\n * Advances the machine by one event. Pure: same inputs always produce an\n * equal output, and the input state is never mutated.\n */\nexport function transition(\n state: ChunkMachineState,\n event: ChunkEvent,\n): ChunkMachineState {\n switch (state.status) {\n case 'idle':\n return transitionIdle(state, event);\n case 'processing':\n return transitionProcessing(state, event);\n case 'paused':\n return transitionPaused(state, event);\n case 'done':\n case 'cancelled':\n case 'error':\n // Terminal: absorb every event and return the same reference, so a\n // React reducer built on this never re-renders for a dead task.\n return state;\n }\n}\n","/**\n * The main-thread yielding primitives this package is built around.\n *\n * Framework-agnostic on purpose: nothing here imports React, so it works\n * just as well inside a Node CLI script chewing through a big array as it\n * does inside a browser tab. The React bindings in `src/react/` are a thin\n * layer on top of this.\n *\n * Strategy, in priority order:\n * 1. `scheduler.yield()` — the purpose-built API (Baseline across Chromium\n * and Firefox as of 2026; continuations resume ahead of same-priority\n * work queued elsewhere on the page).\n * 2. `MessageChannel` — posts a message to a dedicated port and resolves on\n * delivery. Not clamped to the ~4ms floor `setTimeout` gets once timers\n * are nested, so it yields sooner than (2).\n * 3. `setTimeout(0)` — universally available, the floor of the floor.\n *\n * Every feature check below is written so it can never throw on a global\n * that doesn't exist — `typeof x` on an undeclared identifier is safe in\n * JS, and every property access goes through optional chaining. That's what\n * makes this file safe to import under SSR, in a test environment with no\n * DOM, or in a browser that only half-implements one of these APIs.\n */\n\nexport type YieldStrategy = 'scheduler-yield' | 'message-channel' | 'set-timeout';\n\n/** Default time slice: roughly the granularity React's own scheduler uses. */\nexport const DEFAULT_TIME_SLICE_MS = 5;\n\ninterface SchedulerYieldGlobal {\n scheduler?: {\n yield?: () => Promise<void>;\n };\n}\n\ninterface NavigatorSchedulingGlobal {\n navigator?: {\n scheduling?: {\n isInputPending?: () => boolean;\n };\n };\n}\n\n/** True when `scheduler.yield()` is present on this runtime. */\nexport function supportsSchedulerYield(): boolean {\n const schedulerGlobal = (globalThis as SchedulerYieldGlobal).scheduler;\n return typeof schedulerGlobal?.yield === 'function';\n}\n\n/** True when the `MessageChannel` constructor is present on this runtime. */\nexport function supportsMessageChannel(): boolean {\n return typeof MessageChannel === 'function';\n}\n\n/** True when `navigator.scheduling.isInputPending()` is present. */\nexport function supportsInputPending(): boolean {\n const navigatorGlobal = (globalThis as NavigatorSchedulingGlobal).navigator;\n return typeof navigatorGlobal?.scheduling?.isInputPending === 'function';\n}\n\n/**\n * Best-effort read of whether the browser has pending input right now.\n * Returns `false` — never throws — when the API is unavailable or errors,\n * since the caller's fallback (a plain time budget) is always safe.\n */\nexport function isInputPending(): boolean {\n try {\n const navigatorGlobal = (globalThis as NavigatorSchedulingGlobal).navigator;\n return navigatorGlobal?.scheduling?.isInputPending?.() ?? false;\n } catch {\n return false;\n }\n}\n\n/** Picks the best strategy this runtime actually supports. */\nexport function resolveYieldStrategy(): YieldStrategy {\n if (supportsSchedulerYield()) return 'scheduler-yield';\n if (supportsMessageChannel()) return 'message-channel';\n return 'set-timeout';\n}\n\nfunction yieldViaMessageChannel(): Promise<void> {\n return new Promise((resolve) => {\n // A fresh channel per call, deliberately — not a shared module-level\n // singleton. Two chunk schedulers can easily be yielding in the same\n // tick (two independent useChunkedTask calls on one page is a normal\n // app, not an edge case), and a shared port's onmessage handler would\n // get clobbered by whichever call registered second, permanently\n // hanging the first caller's promise. A new MessageChannel is a few\n // microseconds; a silently-hung promise is a production incident.\n const channel = new MessageChannel();\n channel.port1.onmessage = () => {\n resolve();\n };\n channel.port2.postMessage(null);\n });\n}\n\nfunction yieldViaSetTimeout(): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, 0);\n });\n}\n\nexport interface YieldToMainOptions {\n /**\n * Force a specific strategy instead of auto-detecting one. Exists for\n * deterministic tests of each fallback path; application code should\n * leave this unset.\n */\n strategy?: YieldStrategy;\n}\n\n/**\n * Yields control back to the browser's main thread, resolving once the\n * browser has had a chance to handle any pending input, then resuming the\n * caller. Never rejects: a runtime that half-implements `scheduler.yield()`\n * (the property exists but the call throws, or the returned promise\n * rejects) falls through to the next strategy rather than propagating the\n * failure into unrelated application code.\n */\nexport async function yieldToMain(options?: YieldToMainOptions): Promise<void> {\n const strategy = options?.strategy ?? resolveYieldStrategy();\n\n if (strategy === 'scheduler-yield') {\n const schedulerGlobal = (globalThis as SchedulerYieldGlobal).scheduler;\n if (typeof schedulerGlobal?.yield === 'function') {\n try {\n await schedulerGlobal.yield();\n return;\n } catch {\n // Fall through to the next strategy below.\n }\n }\n await (supportsMessageChannel() ? yieldViaMessageChannel() : yieldViaSetTimeout());\n return;\n }\n\n if (strategy === 'message-channel') {\n if (supportsMessageChannel()) {\n await yieldViaMessageChannel();\n return;\n }\n await yieldViaSetTimeout();\n return;\n }\n\n await yieldViaSetTimeout();\n}\n\n/** `performance.now()` when available, `Date.now()` otherwise. Never throws. */\nexport function now(): number {\n try {\n if (typeof performance !== 'undefined' && typeof performance.now === 'function') {\n return performance.now();\n }\n } catch {\n // fall through\n }\n return Date.now();\n}\n\nexport interface ShouldYieldOptions {\n /** `now()` timestamp when the current uninterrupted run of work began. */\n sliceStartedAt: number;\n /** Max ms to run before yielding regardless of input-pending state. */\n timeSliceMs?: number;\n}\n\n/**\n * Whether the caller should yield right now: either the time slice has run\n * out, or the browser is reporting pending input (a stronger, earlier\n * signal than the clock — used only when the runtime exposes it).\n */\nexport function shouldYieldNow(options: ShouldYieldOptions): boolean {\n const timeSliceMs = options.timeSliceMs ?? DEFAULT_TIME_SLICE_MS;\n const elapsed = now() - options.sliceStartedAt;\n if (elapsed >= timeSliceMs) return true;\n return isInputPending();\n}\n","import {\n type ChunkEvent,\n type ChunkMachineState,\n type ChunkStatus,\n initialChunkState,\n isTerminal,\n transition,\n} from './chunk-machine.js';\nimport {\n DEFAULT_TIME_SLICE_MS,\n type YieldStrategy,\n now,\n shouldYieldNow,\n yieldToMain,\n} from './scheduler.js';\n\nexport interface ChunkSchedulerOptions<T, R> {\n readonly items: readonly T[];\n readonly processItem: (item: T, index: number) => R;\n /** Max ms of uninterrupted work before yielding. Default 5. */\n readonly timeSliceMs?: number;\n /** Called after each item is successfully processed. */\n readonly onItem?: (result: R, item: T, index: number) => void;\n /** External cancellation source — aborting it is equivalent to calling cancel(). */\n readonly signal?: AbortSignal;\n /** Testing-only: forces a specific yield strategy instead of auto-detecting one. */\n readonly yieldStrategy?: YieldStrategy;\n}\n\nexport interface ChunkSchedulerResult<R> {\n readonly status: 'done' | 'cancelled' | 'error';\n readonly results: readonly R[];\n readonly error?: unknown;\n}\n\nexport interface ChunkSnapshot {\n readonly status: ChunkStatus;\n readonly processed: number;\n readonly total: number;\n readonly error?: unknown;\n}\n\nexport interface ChunkScheduler<R> {\n start(): void;\n pause(): void;\n resume(): void;\n cancel(): void;\n getSnapshot(): ChunkSnapshot;\n /**\n * The accumulated results, but only once the task has reached a terminal\n * state — `undefined` while idle/processing/paused. Computed once, cheaply,\n * at the moment of that transition; never recomputed on every item, so\n * reading it (e.g. every time the snapshot changes) never costs an O(n)\n * array copy per item for a large task. For incremental consumption while\n * the task is still running, use the `onItem` option instead.\n */\n getResults(): readonly R[] | undefined;\n subscribe(listener: () => void): () => void;\n /** Resolves exactly once, when the task reaches a terminal state. Never rejects. */\n readonly settled: Promise<ChunkSchedulerResult<R>>;\n}\n\nfunction normalizeTimeSliceMs(value: number | undefined): number {\n if (typeof value !== 'number' || Number.isNaN(value) || value <= 0) {\n return DEFAULT_TIME_SLICE_MS;\n }\n return value;\n}\n\n/**\n * Builds a one-shot, controllable scheduler that processes `items` through\n * `processItem`, yielding to the main thread on a time budget (and sooner,\n * if the browser reports pending input) so a large array never produces a\n * single long task.\n *\n * One-shot means exactly that: once the task reaches `done`, `cancelled` or\n * `error`, this instance is finished — start()/pause()/resume() on it are\n * no-ops from then on. To run another task, create another scheduler. For a\n * React hook, that falls out naturally: new deps → new effect → new\n * scheduler, which is the idiomatic React data-flow anyway.\n */\nexport function createChunkScheduler<T, R>(\n options: ChunkSchedulerOptions<T, R>,\n): ChunkScheduler<R> {\n const { items, processItem, onItem, signal, yieldStrategy } = options;\n const timeSliceMs = normalizeTimeSliceMs(options.timeSliceMs);\n const total = items.length;\n\n let machineState: ChunkMachineState = initialChunkState;\n let processed = 0;\n let loopStarted = false;\n let settledFlag = false;\n const results: R[] = [];\n let finalResults: readonly R[] | undefined;\n\n let snapshot: ChunkSnapshot = { status: machineState.status, processed, total };\n const listeners = new Set<() => void>();\n\n let settleFn!: (result: ChunkSchedulerResult<R>) => void;\n const settledPromise = new Promise<ChunkSchedulerResult<R>>((resolve) => {\n settleFn = resolve;\n });\n\n // The gate a paused loop blocks on. Recreated per pause; opened by either\n // resume() or cancel() so a cancelled-while-paused task can never hang.\n let pauseResolve: (() => void) | undefined;\n let pausePromise: Promise<void> | undefined;\n\n function waitForWake(): Promise<void> {\n pausePromise ??= new Promise((resolve) => {\n pauseResolve = resolve;\n });\n return pausePromise;\n }\n\n function openGate(): void {\n pauseResolve?.();\n pauseResolve = undefined;\n pausePromise = undefined;\n }\n\n function notify(): void {\n for (const listener of listeners) listener();\n }\n\n function refreshSnapshot(): void {\n snapshot = {\n status: machineState.status,\n processed,\n total,\n ...(machineState.error !== undefined ? { error: machineState.error } : {}),\n };\n }\n\n function dispatch(event: ChunkEvent): { changed: boolean } {\n const next = transition(machineState, event);\n const changed = next !== machineState;\n if (changed) {\n machineState = next;\n refreshSnapshot();\n notify();\n }\n return { changed };\n }\n\n function settle(result: ChunkSchedulerResult<R>): void {\n // Structurally unreachable, not merely untested: `finish()` — the only\n // caller of `settle()` — is itself only ever reached from one of two\n // mutually exclusive places, each gated by `loopStarted`: runLoop()'s\n // own completion (which only runs after `loopStarted` was already set\n // true by start()) or settleIfNeverStarted() (which refuses to run\n // once `loopStarted` is true). Either way, by the time this instance\n // can ever reach a terminal state the second time, there is no longer\n // any code path left that would call settle() again. Kept anyway as\n // defense-in-depth against a future refactor breaking that invariant.\n /* v8 ignore next */\n if (settledFlag) return;\n settledFlag = true;\n detachSignal();\n settleFn(result);\n }\n\n /**\n * The single path every terminal transition goes through: snapshots the\n * results array exactly once (not per item), publishes it via\n * getResults(), and settles the public promise with the same reference —\n * no redundant second copy.\n */\n function finish(status: 'done' | 'cancelled' | 'error', error?: unknown): void {\n const resultsCopy = [...results];\n finalResults = resultsCopy;\n settle(\n status === 'error'\n ? { status, error, results: resultsCopy }\n : { status, results: resultsCopy },\n );\n }\n\n // If the machine reached a terminal state without the processing loop\n // ever running (e.g. cancel() called before start(), or the signal was\n // already aborted), the loop will never call finish() itself — so this\n // does it. Guarded by !loopStarted, which this also sets, so it can never\n // race with (or double-finish against) the loop's own completion path.\n function settleIfNeverStarted(): void {\n const { status, error } = machineState;\n if (loopStarted || !isTerminal(status)) return;\n loopStarted = true;\n // Both 'done' and 'error' are unreachable here without the loop\n // having run — and the loop having run means `loopStarted` was\n // already true, which would have short-circuited this function above\n // — so 'cancelled' is the only status this ever actually sees. Kept\n // as the real (narrowed) type rather than assumed away, in case that\n // invariant ever changes; the 'error' branch specifically is untestable\n // defense-in-depth for the same structural reason.\n /* v8 ignore next */\n if (status === 'error') finish('error', error);\n else finish(status);\n }\n\n function handleAbort(): void {\n cancel();\n }\n\n function detachSignal(): void {\n signal?.removeEventListener('abort', handleAbort);\n }\n\n if (signal?.aborted) {\n dispatch({ type: 'CANCEL' });\n } else {\n signal?.addEventListener('abort', handleAbort);\n }\n\n async function runLoop(): Promise<void> {\n let sliceStartedAt = now();\n\n itemLoop: for (const [index, item] of items.entries()) {\n // Keep re-checking status for *this same* item until it's neither\n // paused nor cancelled, instead of trusting a single wake-from-pause\n // to mean \"clear to proceed\". A resume() can be undone by a\n // *reentrant* pause() triggered synchronously from a subscriber's\n // own notification (resume() dispatches, notify() runs listeners\n // synchronously, a listener calls pause() before resume() returns)\n // — so without this, the first item after such a resume() would\n // run anyway, even though the task is genuinely paused again by\n // the time it does. A plain `continue` on the outer for-of would\n // wrongly advance to the next item instead of re-checking this one,\n // which is why this is its own inner loop with a labeled break for\n // the one case (cancelled) that must stop processing entirely.\n for (;;) {\n const status: ChunkStatus = machineState.status;\n if (status === 'cancelled') break itemLoop;\n if (status !== 'paused') break;\n await waitForWake();\n sliceStartedAt = now();\n }\n\n try {\n const result = processItem(item, index);\n results.push(result);\n processed = index + 1;\n refreshSnapshot();\n onItem?.(result, item, index);\n } catch (error) {\n dispatch({ type: 'ERROR', error });\n finish('error', error);\n return;\n }\n\n if (shouldYieldNow({ sliceStartedAt, timeSliceMs })) {\n await yieldToMain(\n yieldStrategy !== undefined ? { strategy: yieldStrategy } : undefined,\n );\n notify(); // surface the progress made during this slice\n sliceStartedAt = now();\n }\n }\n\n if (machineState.status === 'cancelled') {\n finish('cancelled');\n return;\n }\n\n dispatch({ type: 'COMPLETE' });\n finish('done');\n }\n\n function start(): void {\n dispatch({ type: 'START' });\n if (machineState.status === 'processing' && !loopStarted) {\n loopStarted = true;\n void runLoop();\n }\n settleIfNeverStarted();\n }\n\n function pause(): void {\n dispatch({ type: 'PAUSE' });\n }\n\n function resume(): void {\n const { changed } = dispatch({ type: 'RESUME' });\n if (changed) openGate();\n }\n\n function cancel(): void {\n dispatch({ type: 'CANCEL' });\n openGate();\n settleIfNeverStarted();\n }\n\n return {\n start,\n pause,\n resume,\n cancel,\n getSnapshot: () => snapshot,\n getResults: () => finalResults,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n settled: settledPromise,\n };\n}\n","import {\n type ChunkEvent,\n type ChunkMachineState,\n type ChunkStatus,\n initialChunkState,\n isTerminal,\n transition,\n} from './chunk-machine.js';\nimport {\n DEFAULT_TIME_SLICE_MS,\n type YieldStrategy,\n now,\n shouldYieldNow,\n yieldToMain,\n} from './scheduler.js';\n\n/**\n * A generator is how you tell `createDeferredTask` where it's safe to yield\n * — arbitrary heavy work (a multi-phase algorithm, a big canvas render)\n * doesn't have a natural \"array of items\" shape the way `createChunkScheduler`\n * expects, so instead you mark checkpoints yourself:\n *\n * ```ts\n * function* renderFrames(frameCount: number) {\n * for (let i = 0; i < frameCount; i++) {\n * renderOneExpensiveFrame(i);\n * yield; // \"it's safe to pause here if we're over budget\"\n * }\n * return frameCount;\n * }\n * ```\n *\n * Everything between two `yield`s runs as one uninterruptible synchronous\n * segment — put them wherever your function can safely stop, the same way\n * you'd think about chunk boundaries by hand, just without writing the\n * scheduling code yourself.\n */\nexport type DeferredGenerator<T> = Generator<void, T, void>;\n\nexport interface DeferredTaskOptions<T> {\n readonly task: () => DeferredGenerator<T>;\n /** Max ms of uninterrupted work before yielding. Default 5. */\n readonly timeSliceMs?: number;\n readonly signal?: AbortSignal;\n /** Testing-only: forces a specific yield strategy instead of auto-detecting one. */\n readonly yieldStrategy?: YieldStrategy;\n}\n\nexport interface DeferredTaskResult<T> {\n readonly status: 'done' | 'cancelled' | 'error';\n readonly value?: T;\n readonly error?: unknown;\n}\n\nexport interface DeferredTaskSnapshot {\n readonly status: ChunkStatus;\n readonly error?: unknown;\n}\n\nexport interface DeferredTask<T> {\n start(): void;\n pause(): void;\n resume(): void;\n cancel(): void;\n getSnapshot(): DeferredTaskSnapshot;\n /** The returned value once the task has settled with `done` — `undefined` otherwise. */\n getValue(): T | undefined;\n subscribe(listener: () => void): () => void;\n readonly settled: Promise<DeferredTaskResult<T>>;\n}\n\nfunction normalizeTimeSliceMs(value: number | undefined): number {\n if (typeof value !== 'number' || Number.isNaN(value) || value <= 0) {\n return DEFAULT_TIME_SLICE_MS;\n }\n return value;\n}\n\n/**\n * The generator-driven sibling of `createChunkScheduler`, for heavy work\n * that isn't shaped like \"one function applied to each item of an array\".\n * Same state machine, same yield primitives, same one-shot-instance\n * contract — see that file's doc comment for the reasoning, which applies\n * here unchanged.\n */\nexport function createDeferredTask<T>(options: DeferredTaskOptions<T>): DeferredTask<T> {\n const { task, signal, yieldStrategy } = options;\n const timeSliceMs = normalizeTimeSliceMs(options.timeSliceMs);\n\n let machineState: ChunkMachineState = initialChunkState;\n let loopStarted = false;\n let settledFlag = false;\n let value: T | undefined;\n\n // Cached, and only rebuilt on an actual transition (see refreshSnapshot())\n // — not recomputed on every getSnapshot() call. useSyncExternalStore\n // requires repeated calls between notifications to return the *same*\n // reference; a fresh object literal on every call (as this used to be)\n // reads as \"changed every render\" and sends React into an infinite\n // re-render loop. Mirrors chunk-scheduler.ts's `snapshot` exactly.\n let snapshot: DeferredTaskSnapshot = { status: machineState.status };\n\n const listeners = new Set<() => void>();\n\n let settleFn!: (result: DeferredTaskResult<T>) => void;\n const settledPromise = new Promise<DeferredTaskResult<T>>((resolve) => {\n settleFn = resolve;\n });\n\n let pauseResolve: (() => void) | undefined;\n let pausePromise: Promise<void> | undefined;\n\n function waitForWake(): Promise<void> {\n pausePromise ??= new Promise((resolve) => {\n pauseResolve = resolve;\n });\n return pausePromise;\n }\n\n function openGate(): void {\n pauseResolve?.();\n pauseResolve = undefined;\n pausePromise = undefined;\n }\n\n function notify(): void {\n for (const listener of listeners) listener();\n }\n\n function refreshSnapshot(): void {\n snapshot = {\n status: machineState.status,\n ...(machineState.error !== undefined ? { error: machineState.error } : {}),\n };\n }\n\n function dispatch(event: ChunkEvent): { changed: boolean } {\n const next = transition(machineState, event);\n const changed = next !== machineState;\n if (changed) {\n machineState = next;\n refreshSnapshot();\n notify();\n }\n return { changed };\n }\n\n function settle(result: DeferredTaskResult<T>): void {\n // Structurally unreachable, not merely untested — see the identical\n // guard in chunk-scheduler.ts's settle() for the full invariant: the\n // only caller, finish(), is reached from exactly one of two mutually\n // exclusive, `loopStarted`-gated paths per instance, so there is never\n // a second call left to make once this instance has settled once.\n // Kept as defense-in-depth against a future refactor breaking that.\n /* v8 ignore next */\n if (settledFlag) return;\n settledFlag = true;\n detachSignal();\n settleFn(result);\n }\n\n function finish(\n status: 'done' | 'cancelled' | 'error',\n resolvedValue?: T,\n error?: unknown,\n ): void {\n if (status === 'done') {\n value = resolvedValue;\n settle({\n status,\n ...(resolvedValue !== undefined ? { value: resolvedValue } : {}),\n });\n return;\n }\n settle(status === 'error' ? { status, error } : { status });\n }\n\n function settleIfNeverStarted(): void {\n const { status, error } = machineState;\n if (loopStarted || !isTerminal(status)) return;\n loopStarted = true;\n // See the identical comment in chunk-scheduler.ts's settleIfNeverStarted():\n // both 'done' and 'error' are unreachable here, since reaching either\n // requires the loop to have run, which requires `loopStarted` already\n // true — which would have short-circuited this function above. Only\n // 'cancelled' is ever actually observed; 'error' is kept as the real,\n // narrowed type rather than assumed away, as untestable defense-in-depth.\n /* v8 ignore next */\n if (status === 'error') finish('error', undefined, error);\n else finish(status);\n }\n\n function handleAbort(): void {\n cancel();\n }\n\n function detachSignal(): void {\n signal?.removeEventListener('abort', handleAbort);\n }\n\n if (signal?.aborted) {\n dispatch({ type: 'CANCEL' });\n } else {\n signal?.addEventListener('abort', handleAbort);\n }\n\n async function runLoop(): Promise<void> {\n let sliceStartedAt = now();\n const generator = task();\n\n // `step` always holds the result of the *last* generator.next() call —\n // including, on an early break below, a stale not-done step from before\n // that break, which the post-loop checks account for explicitly.\n let step: IteratorResult<void, T> = { done: false, value: undefined };\n try {\n for (;;) {\n // Captured once per iteration and compared via this local, not via\n // repeated `machineState.status` property reads — narrowing a\n // direct property access to a literal here would otherwise survive\n // (in TS's eyes) across the `await` below, even though the whole\n // point of that await is that `machineState` can change out from\n // under us while it's pending.\n const status: ChunkStatus = machineState.status;\n if (status === 'cancelled') {\n generator.return(undefined as unknown as T);\n break;\n }\n\n if (status === 'paused') {\n await waitForWake();\n sliceStartedAt = now();\n // Don't fall through to generator.next() just because the gate\n // opened — re-enter the loop and read machineState.status fresh.\n // A resume() can be undone by a *reentrant* pause() triggered\n // synchronously from a subscriber's own notification (resume()\n // dispatches, notify() runs listeners synchronously, a listener\n // calls pause() before resume() returns) — so waking from one\n // gate is not proof we're actually clear to proceed. Looping\n // back here is what lets the top-of-loop checks see that and\n // either re-block on a fresh gate (status is paused again) or\n // notice cancellation, instead of blindly running one more\n // generator step first.\n continue;\n }\n\n // The cancellation check above MUST run before this call, not\n // after: calling the generator is where its actual (synchronous)\n // work for this segment happens. An earlier draft called\n // generator.next() at the *bottom* of the loop, right after the\n // yieldToMain() await below — so a cancel() landing during that\n // await would still let one more segment's worth of work run\n // before the next loop iteration finally noticed. Checking first,\n // every time, closes that race: nothing the generator does can run\n // once cancellation has been observed.\n step = generator.next();\n if (step.done) break;\n\n if (shouldYieldNow({ sliceStartedAt, timeSliceMs })) {\n await yieldToMain(\n yieldStrategy !== undefined ? { strategy: yieldStrategy } : undefined,\n );\n notify();\n sliceStartedAt = now();\n }\n }\n } catch (error) {\n dispatch({ type: 'ERROR', error });\n finish('error', undefined, error);\n return;\n }\n\n if (machineState.status === 'cancelled') {\n finish('cancelled');\n return;\n }\n\n dispatch({ type: 'COMPLETE' });\n // step.done is always true by the time we get here: the only ways out\n // of the loop above are the top-of-loop 'cancelled' break (handled by\n // the early return just above, before this line) and `if (step.done)\n // break;` — so the \": undefined\" side of this ternary can't actually\n // run. It stays only because it's what makes TypeScript narrow\n // step.value's type correctly (see the top of this function's history\n // for the exact inference issue); the real type is kept rather than\n // cast away.\n /* v8 ignore next */\n finish('done', step.done ? step.value : undefined);\n }\n\n function start(): void {\n dispatch({ type: 'START' });\n if (machineState.status === 'processing' && !loopStarted) {\n loopStarted = true;\n void runLoop();\n }\n settleIfNeverStarted();\n }\n\n function pause(): void {\n dispatch({ type: 'PAUSE' });\n }\n\n function resume(): void {\n const { changed } = dispatch({ type: 'RESUME' });\n if (changed) openGate();\n }\n\n function cancel(): void {\n dispatch({ type: 'CANCEL' });\n openGate();\n settleIfNeverStarted();\n }\n\n return {\n start,\n pause,\n resume,\n cancel,\n getSnapshot: () => snapshot,\n getValue: () => value,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n settled: settledPromise,\n };\n}\n"],"mappings":";AAyCA,MAAa,oBAAuC,EAAE,QAAQ,OAAO;AAIrE,MAAM,oCAA8C,IAAI,IAAiB;CACvE;CACA;CACA;AACF,CAAC;AAED,SAAgB,WAAW,QAAoD;CAC7E,OAAO,kBAAkB,IAAI,MAAM;AACrC;AAEA,SAAS,eAAe,OAA0B,OAAsC;CACtF,QAAQ,MAAM,MAAd;EACE,KAAK,SACH,OAAO,EAAE,QAAQ,aAAa;EAChC,KAAK,UACH,OAAO,EAAE,QAAQ,YAAY;EAC/B,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,OAAO;CACX;AACF;AAEA,SAAS,qBACP,OACA,OACmB;CACnB,QAAQ,MAAM,MAAd;EACE,KAAK,SACH,OAAO,EAAE,QAAQ,SAAS;EAC5B,KAAK,UACH,OAAO,EAAE,QAAQ,YAAY;EAC/B,KAAK,YACH,OAAO,EAAE,QAAQ,OAAO;EAC1B,KAAK,SACH,OAAO;GAAE,QAAQ;GAAS,OAAO,MAAM;EAAM;EAC/C,KAAK;EACL,KAAK,UACH,OAAO;CACX;AACF;AAEA,SAAS,iBACP,OACA,OACmB;CACnB,QAAQ,MAAM,MAAd;EACE,KAAK,UACH,OAAO,EAAE,QAAQ,aAAa;EAChC,KAAK,UACH,OAAO,EAAE,QAAQ,YAA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SAAS,QAAc;EACrB,SAAS,EAAE,MAAM,QAAQ,CAAC;EAC1B,IAAI,aAAa,WAAW,gBAAgB,CAAC,aAAa;GACxD,cAAc;GACd,QAAa;EACf;EACA,qBAAqB;CACvB;CAEA,SAAS,QAAc;EACrB,SAAS,EAAE,MAAM,QAAQ,CAAC;CAC5B;CAEA,SAAS,SAAe;EACtB,MAAM,EAAE,YAAY,SAAS,EAAE,MAAM,SAAS,CAAC;EAC/C,IAAI,SAAS,SAAS;CACxB;CAEA,SAAS,SAAe;EACtB,SAAS,EAAE,MAAM,SAAS,CAAC;EAC3B,SAAS;EACT,qBAAqB;CACvB;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA,mBAAmB;EACnB,gBAAgB;EAChB,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,SAAS;CACX;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"deferred-task-BXVzapQg.cjs","names":["normalizeTimeSliceMs"],"sources":["../src/core/chunk-machine.ts","../src/core/scheduler.ts","../src/core/chunk-scheduler.ts","../src/core/deferred-task.ts"],"sourcesContent":["/**\n * The state machine a chunk task moves through. Deliberately separate from\n * `chunk-scheduler.ts`'s async orchestration: this file is pure, synchronous,\n * and has nothing to fake-timer around, which is what makes it possible to\n * exhaustively test every (state, event) pair — all of them, not a sample.\n *\n * START CANCEL\n * idle ---------> processing ----------------> cancelled\n * | ^ ^ ^\n * PAUSE | | RESUME CANCEL| | CANCEL\n * v | | |\n * paused -+-------------------+ |\n * | |\n * COMPLETE | ERROR |\n * v |\n * done / error (terminal, absorb everything)\n *\n * `done`, `cancelled` and `error` are terminal: once reached, every further\n * event is a no-op that returns the same state object (referentially equal,\n * so a React reducer built on this never re-renders for a dead task). A\n * scheduler is one-shot by design — to run another task, create another\n * scheduler. That one rule is what keeps this table small enough to verify\n * completely instead of \"pretty thoroughly\".\n */\n\nexport type ChunkStatus =\n 'idle' | 'processing' | 'paused' | 'done' | 'cancelled' | 'error';\n\nexport type ChunkEvent =\n | { readonly type: 'START' }\n | { readonly type: 'PAUSE' }\n | { readonly type: 'RESUME' }\n | { readonly type: 'CANCEL' }\n | { readonly type: 'COMPLETE' }\n | { readonly type: 'ERROR'; readonly error: unknown };\n\nexport interface ChunkMachineState {\n readonly status: ChunkStatus;\n readonly error?: unknown;\n}\n\nexport const initialChunkState: ChunkMachineState = { status: 'idle' };\n\nexport type TerminalChunkStatus = 'done' | 'cancelled' | 'error';\n\nconst TERMINAL_STATUSES: ReadonlySet<ChunkStatus> = new Set<ChunkStatus>([\n 'done',\n 'cancelled',\n 'error',\n]);\n\nexport function isTerminal(status: ChunkStatus): status is TerminalChunkStatus {\n return TERMINAL_STATUSES.has(status);\n}\n\nfunction transitionIdle(state: ChunkMachineState, event: ChunkEvent): ChunkMachineState {\n switch (event.type) {\n case 'START':\n return { status: 'processing' };\n case 'CANCEL':\n return { status: 'cancelled' };\n case 'PAUSE':\n case 'RESUME':\n case 'COMPLETE':\n case 'ERROR':\n return state;\n }\n}\n\nfunction transitionProcessing(\n state: ChunkMachineState,\n event: ChunkEvent,\n): ChunkMachineState {\n switch (event.type) {\n case 'PAUSE':\n return { status: 'paused' };\n case 'CANCEL':\n return { status: 'cancelled' };\n case 'COMPLETE':\n return { status: 'done' };\n case 'ERROR':\n return { status: 'error', error: event.error };\n case 'START':\n case 'RESUME':\n return state;\n }\n}\n\nfunction transitionPaused(\n state: ChunkMachineState,\n event: ChunkEvent,\n): ChunkMachineState {\n switch (event.type) {\n case 'RESUME':\n return { status: 'processing' };\n case 'CANCEL':\n return { status: 'cancelled' };\n case 'START':\n case 'PAUSE':\n case 'COMPLETE':\n case 'ERROR':\n return state;\n }\n}\n\n/**\n * Advances the machine by one event. Pure: same inputs always produce an\n * equal output, and the input state is never mutated.\n */\nexport function transition(\n state: ChunkMachineState,\n event: ChunkEvent,\n): ChunkMachineState {\n switch (state.status) {\n case 'idle':\n return transitionIdle(state, event);\n case 'processing':\n return transitionProcessing(state, event);\n case 'paused':\n return transitionPaused(state, event);\n case 'done':\n case 'cancelled':\n case 'error':\n // Terminal: absorb every event and return the same reference, so a\n // React reducer built on this never re-renders for a dead task.\n return state;\n }\n}\n","/**\n * The main-thread yielding primitives this package is built around.\n *\n * Framework-agnostic on purpose: nothing here imports React, so it works\n * just as well inside a Node CLI script chewing through a big array as it\n * does inside a browser tab. The React bindings in `src/react/` are a thin\n * layer on top of this.\n *\n * Strategy, in priority order:\n * 1. `scheduler.yield()` — the purpose-built API (Baseline across Chromium\n * and Firefox as of 2026; continuations resume ahead of same-priority\n * work queued elsewhere on the page).\n * 2. `MessageChannel` — posts a message to a dedicated port and resolves on\n * delivery. Not clamped to the ~4ms floor `setTimeout` gets once timers\n * are nested, so it yields sooner than (2).\n * 3. `setTimeout(0)` — universally available, the floor of the floor.\n *\n * Every feature check below is written so it can never throw on a global\n * that doesn't exist — `typeof x` on an undeclared identifier is safe in\n * JS, and every property access goes through optional chaining. That's what\n * makes this file safe to import under SSR, in a test environment with no\n * DOM, or in a browser that only half-implements one of these APIs.\n */\n\nexport type YieldStrategy = 'scheduler-yield' | 'message-channel' | 'set-timeout';\n\n/** Default time slice: roughly the granularity React's own scheduler uses. */\nexport const DEFAULT_TIME_SLICE_MS = 5;\n\ninterface SchedulerYieldGlobal {\n scheduler?: {\n yield?: () => Promise<void>;\n };\n}\n\ninterface NavigatorSchedulingGlobal {\n navigator?: {\n scheduling?: {\n isInputPending?: () => boolean;\n };\n };\n}\n\n/** True when `scheduler.yield()` is present on this runtime. */\nexport function supportsSchedulerYield(): boolean {\n const schedulerGlobal = (globalThis as SchedulerYieldGlobal).scheduler;\n return typeof schedulerGlobal?.yield === 'function';\n}\n\n/** True when the `MessageChannel` constructor is present on this runtime. */\nexport function supportsMessageChannel(): boolean {\n return typeof MessageChannel === 'function';\n}\n\n/** True when `navigator.scheduling.isInputPending()` is present. */\nexport function supportsInputPending(): boolean {\n const navigatorGlobal = (globalThis as NavigatorSchedulingGlobal).navigator;\n return typeof navigatorGlobal?.scheduling?.isInputPending === 'function';\n}\n\n/**\n * Best-effort read of whether the browser has pending input right now.\n * Returns `false` — never throws — when the API is unavailable or errors,\n * since the caller's fallback (a plain time budget) is always safe.\n */\nexport function isInputPending(): boolean {\n try {\n const navigatorGlobal = (globalThis as NavigatorSchedulingGlobal).navigator;\n return navigatorGlobal?.scheduling?.isInputPending?.() ?? false;\n } catch {\n return false;\n }\n}\n\n/** Picks the best strategy this runtime actually supports. */\nexport function resolveYieldStrategy(): YieldStrategy {\n if (supportsSchedulerYield()) return 'scheduler-yield';\n if (supportsMessageChannel()) return 'message-channel';\n return 'set-timeout';\n}\n\nfunction yieldViaMessageChannel(): Promise<void> {\n return new Promise((resolve) => {\n // A fresh channel per call, deliberately — not a shared module-level\n // singleton. Two chunk schedulers can easily be yielding in the same\n // tick (two independent useChunkedTask calls on one page is a normal\n // app, not an edge case), and a shared port's onmessage handler would\n // get clobbered by whichever call registered second, permanently\n // hanging the first caller's promise. A new MessageChannel is a few\n // microseconds; a silently-hung promise is a production incident.\n const channel = new MessageChannel();\n channel.port1.onmessage = () => {\n resolve();\n };\n channel.port2.postMessage(null);\n });\n}\n\nfunction yieldViaSetTimeout(): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, 0);\n });\n}\n\nexport interface YieldToMainOptions {\n /**\n * Force a specific strategy instead of auto-detecting one. Exists for\n * deterministic tests of each fallback path; application code should\n * leave this unset.\n */\n strategy?: YieldStrategy;\n}\n\n/**\n * Yields control back to the browser's main thread, resolving once the\n * browser has had a chance to handle any pending input, then resuming the\n * caller. Never rejects: a runtime that half-implements `scheduler.yield()`\n * (the property exists but the call throws, or the returned promise\n * rejects) falls through to the next strategy rather than propagating the\n * failure into unrelated application code.\n */\nexport async function yieldToMain(options?: YieldToMainOptions): Promise<void> {\n const strategy = options?.strategy ?? resolveYieldStrategy();\n\n if (strategy === 'scheduler-yield') {\n const schedulerGlobal = (globalThis as SchedulerYieldGlobal).scheduler;\n if (typeof schedulerGlobal?.yield === 'function') {\n try {\n await schedulerGlobal.yield();\n return;\n } catch {\n // Fall through to the next strategy below.\n }\n }\n await (supportsMessageChannel() ? yieldViaMessageChannel() : yieldViaSetTimeout());\n return;\n }\n\n if (strategy === 'message-channel') {\n if (supportsMessageChannel()) {\n await yieldViaMessageChannel();\n return;\n }\n await yieldViaSetTimeout();\n return;\n }\n\n await yieldViaSetTimeout();\n}\n\n/** `performance.now()` when available, `Date.now()` otherwise. Never throws. */\nexport function now(): number {\n try {\n if (typeof performance !== 'undefined' && typeof performance.now === 'function') {\n return performance.now();\n }\n } catch {\n // fall through\n }\n return Date.now();\n}\n\nexport interface ShouldYieldOptions {\n /** `now()` timestamp when the current uninterrupted run of work began. */\n sliceStartedAt: number;\n /** Max ms to run before yielding regardless of input-pending state. */\n timeSliceMs?: number;\n}\n\n/**\n * Whether the caller should yield right now: either the time slice has run\n * out, or the browser is reporting pending input (a stronger, earlier\n * signal than the clock — used only when the runtime exposes it).\n */\nexport function shouldYieldNow(options: ShouldYieldOptions): boolean {\n const timeSliceMs = options.timeSliceMs ?? DEFAULT_TIME_SLICE_MS;\n const elapsed = now() - options.sliceStartedAt;\n if (elapsed >= timeSliceMs) return true;\n return isInputPending();\n}\n","import {\n type ChunkEvent,\n type ChunkMachineState,\n type ChunkStatus,\n initialChunkState,\n isTerminal,\n transition,\n} from './chunk-machine.js';\nimport {\n DEFAULT_TIME_SLICE_MS,\n type YieldStrategy,\n now,\n shouldYieldNow,\n yieldToMain,\n} from './scheduler.js';\n\nexport interface ChunkSchedulerOptions<T, R> {\n readonly items: readonly T[];\n readonly processItem: (item: T, index: number) => R;\n /** Max ms of uninterrupted work before yielding. Default 5. */\n readonly timeSliceMs?: number;\n /** Called after each item is successfully processed. */\n readonly onItem?: (result: R, item: T, index: number) => void;\n /** External cancellation source — aborting it is equivalent to calling cancel(). */\n readonly signal?: AbortSignal;\n /** Testing-only: forces a specific yield strategy instead of auto-detecting one. */\n readonly yieldStrategy?: YieldStrategy;\n}\n\nexport interface ChunkSchedulerResult<R> {\n readonly status: 'done' | 'cancelled' | 'error';\n readonly results: readonly R[];\n readonly error?: unknown;\n}\n\nexport interface ChunkSnapshot {\n readonly status: ChunkStatus;\n readonly processed: number;\n readonly total: number;\n readonly error?: unknown;\n}\n\nexport interface ChunkScheduler<R> {\n start(): void;\n pause(): void;\n resume(): void;\n cancel(): void;\n getSnapshot(): ChunkSnapshot;\n /**\n * The accumulated results, but only once the task has reached a terminal\n * state — `undefined` while idle/processing/paused. Computed once, cheaply,\n * at the moment of that transition; never recomputed on every item, so\n * reading it (e.g. every time the snapshot changes) never costs an O(n)\n * array copy per item for a large task. For incremental consumption while\n * the task is still running, use the `onItem` option instead.\n */\n getResults(): readonly R[] | undefined;\n subscribe(listener: () => void): () => void;\n /** Resolves exactly once, when the task reaches a terminal state. Never rejects. */\n readonly settled: Promise<ChunkSchedulerResult<R>>;\n}\n\nfunction normalizeTimeSliceMs(value: number | undefined): number {\n if (typeof value !== 'number' || Number.isNaN(value) || value <= 0) {\n return DEFAULT_TIME_SLICE_MS;\n }\n return value;\n}\n\n/**\n * Builds a one-shot, controllable scheduler that processes `items` through\n * `processItem`, yielding to the main thread on a time budget (and sooner,\n * if the browser reports pending input) so a large array never produces a\n * single long task.\n *\n * One-shot means exactly that: once the task reaches `done`, `cancelled` or\n * `error`, this instance is finished — start()/pause()/resume() on it are\n * no-ops from then on. To run another task, create another scheduler. For a\n * React hook, that falls out naturally: new deps → new effect → new\n * scheduler, which is the idiomatic React data-flow anyway.\n */\nexport function createChunkScheduler<T, R>(\n options: ChunkSchedulerOptions<T, R>,\n): ChunkScheduler<R> {\n const { items, processItem, onItem, signal, yieldStrategy } = options;\n const timeSliceMs = normalizeTimeSliceMs(options.timeSliceMs);\n const total = items.length;\n\n let machineState: ChunkMachineState = initialChunkState;\n let processed = 0;\n let loopStarted = false;\n let settledFlag = false;\n const results: R[] = [];\n let finalResults: readonly R[] | undefined;\n\n let snapshot: ChunkSnapshot = { status: machineState.status, processed, total };\n const listeners = new Set<() => void>();\n\n let settleFn!: (result: ChunkSchedulerResult<R>) => void;\n const settledPromise = new Promise<ChunkSchedulerResult<R>>((resolve) => {\n settleFn = resolve;\n });\n\n // The gate a paused loop blocks on. Recreated per pause; opened by either\n // resume() or cancel() so a cancelled-while-paused task can never hang.\n let pauseResolve: (() => void) | undefined;\n let pausePromise: Promise<void> | undefined;\n\n function waitForWake(): Promise<void> {\n pausePromise ??= new Promise((resolve) => {\n pauseResolve = resolve;\n });\n return pausePromise;\n }\n\n function openGate(): void {\n pauseResolve?.();\n pauseResolve = undefined;\n pausePromise = undefined;\n }\n\n function notify(): void {\n for (const listener of listeners) listener();\n }\n\n function refreshSnapshot(): void {\n snapshot = {\n status: machineState.status,\n processed,\n total,\n ...(machineState.error !== undefined ? { error: machineState.error } : {}),\n };\n }\n\n function dispatch(event: ChunkEvent): { changed: boolean } {\n const next = transition(machineState, event);\n const changed = next !== machineState;\n if (changed) {\n machineState = next;\n refreshSnapshot();\n notify();\n }\n return { changed };\n }\n\n function settle(result: ChunkSchedulerResult<R>): void {\n // Structurally unreachable, not merely untested: `finish()` — the only\n // caller of `settle()` — is itself only ever reached from one of two\n // mutually exclusive places, each gated by `loopStarted`: runLoop()'s\n // own completion (which only runs after `loopStarted` was already set\n // true by start()) or settleIfNeverStarted() (which refuses to run\n // once `loopStarted` is true). Either way, by the time this instance\n // can ever reach a terminal state the second time, there is no longer\n // any code path left that would call settle() again. Kept anyway as\n // defense-in-depth against a future refactor breaking that invariant.\n /* v8 ignore next */\n if (settledFlag) return;\n settledFlag = true;\n detachSignal();\n settleFn(result);\n }\n\n /**\n * The single path every terminal transition goes through: snapshots the\n * results array exactly once (not per item), publishes it via\n * getResults(), and settles the public promise with the same reference —\n * no redundant second copy.\n */\n function finish(status: 'done' | 'cancelled' | 'error', error?: unknown): void {\n const resultsCopy = [...results];\n finalResults = resultsCopy;\n settle(\n status === 'error'\n ? { status, error, results: resultsCopy }\n : { status, results: resultsCopy },\n );\n }\n\n // If the machine reached a terminal state without the processing loop\n // ever running (e.g. cancel() called before start(), or the signal was\n // already aborted), the loop will never call finish() itself — so this\n // does it. Guarded by !loopStarted, which this also sets, so it can never\n // race with (or double-finish against) the loop's own completion path.\n function settleIfNeverStarted(): void {\n const { status, error } = machineState;\n if (loopStarted || !isTerminal(status)) return;\n loopStarted = true;\n // Both 'done' and 'error' are unreachable here without the loop\n // having run — and the loop having run means `loopStarted` was\n // already true, which would have short-circuited this function above\n // — so 'cancelled' is the only status this ever actually sees. Kept\n // as the real (narrowed) type rather than assumed away, in case that\n // invariant ever changes; the 'error' branch specifically is untestable\n // defense-in-depth for the same structural reason.\n /* v8 ignore next */\n if (status === 'error') finish('error', error);\n else finish(status);\n }\n\n function handleAbort(): void {\n cancel();\n }\n\n function detachSignal(): void {\n signal?.removeEventListener('abort', handleAbort);\n }\n\n if (signal?.aborted) {\n dispatch({ type: 'CANCEL' });\n } else {\n signal?.addEventListener('abort', handleAbort);\n }\n\n async function runLoop(): Promise<void> {\n let sliceStartedAt = now();\n\n itemLoop: for (const [index, item] of items.entries()) {\n // Keep re-checking status for *this same* item until it's neither\n // paused nor cancelled, instead of trusting a single wake-from-pause\n // to mean \"clear to proceed\". A resume() can be undone by a\n // *reentrant* pause() triggered synchronously from a subscriber's\n // own notification (resume() dispatches, notify() runs listeners\n // synchronously, a listener calls pause() before resume() returns)\n // — so without this, the first item after such a resume() would\n // run anyway, even though the task is genuinely paused again by\n // the time it does. A plain `continue` on the outer for-of would\n // wrongly advance to the next item instead of re-checking this one,\n // which is why this is its own inner loop with a labeled break for\n // the one case (cancelled) that must stop processing entirely.\n for (;;) {\n const status: ChunkStatus = machineState.status;\n if (status === 'cancelled') break itemLoop;\n if (status !== 'paused') break;\n await waitForWake();\n sliceStartedAt = now();\n }\n\n try {\n const result = processItem(item, index);\n results.push(result);\n processed = index + 1;\n refreshSnapshot();\n onItem?.(result, item, index);\n } catch (error) {\n dispatch({ type: 'ERROR', error });\n finish('error', error);\n return;\n }\n\n if (shouldYieldNow({ sliceStartedAt, timeSliceMs })) {\n await yieldToMain(\n yieldStrategy !== undefined ? { strategy: yieldStrategy } : undefined,\n );\n notify(); // surface the progress made during this slice\n sliceStartedAt = now();\n }\n }\n\n if (machineState.status === 'cancelled') {\n finish('cancelled');\n return;\n }\n\n dispatch({ type: 'COMPLETE' });\n finish('done');\n }\n\n function start(): void {\n dispatch({ type: 'START' });\n if (machineState.status === 'processing' && !loopStarted) {\n loopStarted = true;\n void runLoop();\n }\n settleIfNeverStarted();\n }\n\n function pause(): void {\n dispatch({ type: 'PAUSE' });\n }\n\n function resume(): void {\n const { changed } = dispatch({ type: 'RESUME' });\n if (changed) openGate();\n }\n\n function cancel(): void {\n dispatch({ type: 'CANCEL' });\n openGate();\n settleIfNeverStarted();\n }\n\n return {\n start,\n pause,\n resume,\n cancel,\n getSnapshot: () => snapshot,\n getResults: () => finalResults,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n settled: settledPromise,\n };\n}\n","import {\n type ChunkEvent,\n type ChunkMachineState,\n type ChunkStatus,\n initialChunkState,\n isTerminal,\n transition,\n} from './chunk-machine.js';\nimport {\n DEFAULT_TIME_SLICE_MS,\n type YieldStrategy,\n now,\n shouldYieldNow,\n yieldToMain,\n} from './scheduler.js';\n\n/**\n * A generator is how you tell `createDeferredTask` where it's safe to yield\n * — arbitrary heavy work (a multi-phase algorithm, a big canvas render)\n * doesn't have a natural \"array of items\" shape the way `createChunkScheduler`\n * expects, so instead you mark checkpoints yourself:\n *\n * ```ts\n * function* renderFrames(frameCount: number) {\n * for (let i = 0; i < frameCount; i++) {\n * renderOneExpensiveFrame(i);\n * yield; // \"it's safe to pause here if we're over budget\"\n * }\n * return frameCount;\n * }\n * ```\n *\n * Everything between two `yield`s runs as one uninterruptible synchronous\n * segment — put them wherever your function can safely stop, the same way\n * you'd think about chunk boundaries by hand, just without writing the\n * scheduling code yourself.\n */\nexport type DeferredGenerator<T> = Generator<void, T, void>;\n\nexport interface DeferredTaskOptions<T> {\n readonly task: () => DeferredGenerator<T>;\n /** Max ms of uninterrupted work before yielding. Default 5. */\n readonly timeSliceMs?: number;\n readonly signal?: AbortSignal;\n /** Testing-only: forces a specific yield strategy instead of auto-detecting one. */\n readonly yieldStrategy?: YieldStrategy;\n}\n\nexport interface DeferredTaskResult<T> {\n readonly status: 'done' | 'cancelled' | 'error';\n readonly value?: T;\n readonly error?: unknown;\n}\n\nexport interface DeferredTaskSnapshot {\n readonly status: ChunkStatus;\n readonly error?: unknown;\n}\n\nexport interface DeferredTask<T> {\n start(): void;\n pause(): void;\n resume(): void;\n cancel(): void;\n getSnapshot(): DeferredTaskSnapshot;\n /** The returned value once the task has settled with `done` — `undefined` otherwise. */\n getValue(): T | undefined;\n subscribe(listener: () => void): () => void;\n readonly settled: Promise<DeferredTaskResult<T>>;\n}\n\nfunction normalizeTimeSliceMs(value: number | undefined): number {\n if (typeof value !== 'number' || Number.isNaN(value) || value <= 0) {\n return DEFAULT_TIME_SLICE_MS;\n }\n return value;\n}\n\n/**\n * The generator-driven sibling of `createChunkScheduler`, for heavy work\n * that isn't shaped like \"one function applied to each item of an array\".\n * Same state machine, same yield primitives, same one-shot-instance\n * contract — see that file's doc comment for the reasoning, which applies\n * here unchanged.\n */\nexport function createDeferredTask<T>(options: DeferredTaskOptions<T>): DeferredTask<T> {\n const { task, signal, yieldStrategy } = options;\n const timeSliceMs = normalizeTimeSliceMs(options.timeSliceMs);\n\n let machineState: ChunkMachineState = initialChunkState;\n let loopStarted = false;\n let settledFlag = false;\n let value: T | undefined;\n\n // Cached, and only rebuilt on an actual transition (see refreshSnapshot())\n // — not recomputed on every getSnapshot() call. useSyncExternalStore\n // requires repeated calls between notifications to return the *same*\n // reference; a fresh object literal on every call (as this used to be)\n // reads as \"changed every render\" and sends React into an infinite\n // re-render loop. Mirrors chunk-scheduler.ts's `snapshot` exactly.\n let snapshot: DeferredTaskSnapshot = { status: machineState.status };\n\n const listeners = new Set<() => void>();\n\n let settleFn!: (result: DeferredTaskResult<T>) => void;\n const settledPromise = new Promise<DeferredTaskResult<T>>((resolve) => {\n settleFn = resolve;\n });\n\n let pauseResolve: (() => void) | undefined;\n let pausePromise: Promise<void> | undefined;\n\n function waitForWake(): Promise<void> {\n pausePromise ??= new Promise((resolve) => {\n pauseResolve = resolve;\n });\n return pausePromise;\n }\n\n function openGate(): void {\n pauseResolve?.();\n pauseResolve = undefined;\n pausePromise = undefined;\n }\n\n function notify(): void {\n for (const listener of listeners) listener();\n }\n\n function refreshSnapshot(): void {\n snapshot = {\n status: machineState.status,\n ...(machineState.error !== undefined ? { error: machineState.error } : {}),\n };\n }\n\n function dispatch(event: ChunkEvent): { changed: boolean } {\n const next = transition(machineState, event);\n const changed = next !== machineState;\n if (changed) {\n machineState = next;\n refreshSnapshot();\n notify();\n }\n return { changed };\n }\n\n function settle(result: DeferredTaskResult<T>): void {\n // Structurally unreachable, not merely untested — see the identical\n // guard in chunk-scheduler.ts's settle() for the full invariant: the\n // only caller, finish(), is reached from exactly one of two mutually\n // exclusive, `loopStarted`-gated paths per instance, so there is never\n // a second call left to make once this instance has settled once.\n // Kept as defense-in-depth against a future refactor breaking that.\n /* v8 ignore next */\n if (settledFlag) return;\n settledFlag = true;\n detachSignal();\n settleFn(result);\n }\n\n function finish(\n status: 'done' | 'cancelled' | 'error',\n resolvedValue?: T,\n error?: unknown,\n ): void {\n if (status === 'done') {\n value = resolvedValue;\n settle({\n status,\n ...(resolvedValue !== undefined ? { value: resolvedValue } : {}),\n });\n return;\n }\n settle(status === 'error' ? { status, error } : { status });\n }\n\n function settleIfNeverStarted(): void {\n const { status, error } = machineState;\n if (loopStarted || !isTerminal(status)) return;\n loopStarted = true;\n // See the identical comment in chunk-scheduler.ts's settleIfNeverStarted():\n // both 'done' and 'error' are unreachable here, since reaching either\n // requires the loop to have run, which requires `loopStarted` already\n // true — which would have short-circuited this function above. Only\n // 'cancelled' is ever actually observed; 'error' is kept as the real,\n // narrowed type rather than assumed away, as untestable defense-in-depth.\n /* v8 ignore next */\n if (status === 'error') finish('error', undefined, error);\n else finish(status);\n }\n\n function handleAbort(): void {\n cancel();\n }\n\n function detachSignal(): void {\n signal?.removeEventListener('abort', handleAbort);\n }\n\n if (signal?.aborted) {\n dispatch({ type: 'CANCEL' });\n } else {\n signal?.addEventListener('abort', handleAbort);\n }\n\n async function runLoop(): Promise<void> {\n let sliceStartedAt = now();\n const generator = task();\n\n // `step` always holds the result of the *last* generator.next() call —\n // including, on an early break below, a stale not-done step from before\n // that break, which the post-loop checks account for explicitly.\n let step: IteratorResult<void, T> = { done: false, value: undefined };\n try {\n for (;;) {\n // Captured once per iteration and compared via this local, not via\n // repeated `machineState.status` property reads — narrowing a\n // direct property access to a literal here would otherwise survive\n // (in TS's eyes) across the `await` below, even though the whole\n // point of that await is that `machineState` can change out from\n // under us while it's pending.\n const status: ChunkStatus = machineState.status;\n if (status === 'cancelled') {\n generator.return(undefined as unknown as T);\n break;\n }\n\n if (status === 'paused') {\n await waitForWake();\n sliceStartedAt = now();\n // Don't fall through to generator.next() just because the gate\n // opened — re-enter the loop and read machineState.status fresh.\n // A resume() can be undone by a *reentrant* pause() triggered\n // synchronously from a subscriber's own notification (resume()\n // dispatches, notify() runs listeners synchronously, a listener\n // calls pause() before resume() returns) — so waking from one\n // gate is not proof we're actually clear to proceed. Looping\n // back here is what lets the top-of-loop checks see that and\n // either re-block on a fresh gate (status is paused again) or\n // notice cancellation, instead of blindly running one more\n // generator step first.\n continue;\n }\n\n // The cancellation check above MUST run before this call, not\n // after: calling the generator is where its actual (synchronous)\n // work for this segment happens. An earlier draft called\n // generator.next() at the *bottom* of the loop, right after the\n // yieldToMain() await below — so a cancel() landing during that\n // await would still let one more segment's worth of work run\n // before the next loop iteration finally noticed. Checking first,\n // every time, closes that race: nothing the generator does can run\n // once cancellation has been observed.\n step = generator.next();\n if (step.done) break;\n\n if (shouldYieldNow({ sliceStartedAt, timeSliceMs })) {\n await yieldToMain(\n yieldStrategy !== undefined ? { strategy: yieldStrategy } : undefined,\n );\n notify();\n sliceStartedAt = now();\n }\n }\n } catch (error) {\n dispatch({ type: 'ERROR', error });\n finish('error', undefined, error);\n return;\n }\n\n if (machineState.status === 'cancelled') {\n finish('cancelled');\n return;\n }\n\n dispatch({ type: 'COMPLETE' });\n // step.done is always true by the time we get here: the only ways out\n // of the loop above are the top-of-loop 'cancelled' break (handled by\n // the early return just above, before this line) and `if (step.done)\n // break;` — so the \": undefined\" side of this ternary can't actually\n // run. It stays only because it's what makes TypeScript narrow\n // step.value's type correctly (see the top of this function's history\n // for the exact inference issue); the real type is kept rather than\n // cast away.\n /* v8 ignore next */\n finish('done', step.done ? step.value : undefined);\n }\n\n function start(): void {\n dispatch({ type: 'START' });\n if (machineState.status === 'processing' && !loopStarted) {\n loopStarted = true;\n void runLoop();\n }\n settleIfNeverStarted();\n }\n\n function pause(): void {\n dispatch({ type: 'PAUSE' });\n }\n\n function resume(): void {\n const { changed } = dispatch({ type: 'RESUME' });\n if (changed) openGate();\n }\n\n function cancel(): void {\n dispatch({ type: 'CANCEL' });\n openGate();\n settleIfNeverStarted();\n }\n\n return {\n start,\n pause,\n resume,\n cancel,\n getSnapshot: () => snapshot,\n getValue: () => value,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n settled: settledPromise,\n };\n}\n"],"mappings":";AAyCA,MAAa,oBAAuC,EAAE,QAAQ,OAAO;AAIrE,MAAM,oCAA8C,IAAI,IAAiB;CACvE;CACA;CACA;AACF,CAAC;AAED,SAAgB,WAAW,QAAoD;CAC7E,OAAO,kBAAkB,IAAI,MAAM;AACrC;AAEA,SAAS,eAAe,OAA0B,OAAsC;CACtF,QAAQ,MAAM,MAAd;EACE,KAAK,SACH,OAAO,EAAE,QAAQ,aAAa;EAChC,KAAK,UACH,OAAO,EAAE,QAAQ,YAAY;EAC/B,K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,OAAO,UAAU,KAAK;IACtB,IAAI,KAAK,MAAM;IAEf,IAAI,eAAe;KAAE;KAAgB;IAAY,CAAC,GAAG;KACnD,MAAM,YACJ,kBAAkB,KAAA,IAAY,EAAE,UAAU,cAAc,IAAI,KAAA,CAC9D;KACA,OAAO;KACP,iBAAiB,IAAI;IACvB;GACF;EACF,SAAS,OAAO;GACd,SAAS;IAAE,MAAM;IAAS;GAAM,CAAC;GACjC,OAAO,SAAS,KAAA,GAAW,KAAK;GAChC;EACF;EAEA,IAAI,aAAa,WAAW,aAAa;GACvC,OAAO,WAAW;GAClB;EACF;EAEA,SAAS,EAAE,MAAM,WAAW,CAAC;;EAU7B,OAAO,QAAQ,KAAK,OAAO,KAAK,QAAQ,KAAA,CAAS;CACnD;CAEA,SAAS,QAAc;EACrB,SAAS,EAAE,MAAM,QAAQ,CAAC;EAC1B,IAAI,aAAa,WAAW,gBAAgB,CAAC,aAAa;GACxD,cAAc;GACd,QAAa;EACf;EACA,qBAAqB;CACvB;CAEA,SAAS,QAAc;EACrB,SAAS,EAAE,MAAM,QAAQ,CAAC;CAC5B;CAEA,SAAS,SAAe;EACtB,MAAM,EAAE,YAAY,SAAS,EAAE,MAAM,SAAS,CAAC;EAC/C,IAAI,SAAS,SAAS;CACxB;CAEA,SAAS,SAAe;EACtB,SAAS,EAAE,MAAM,SAAS,CAAC;EAC3B,SAAS;EACT,qBAAqB;CACvB;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA,mBAAmB;EACnB,gBAAgB;EAChB,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,SAAS;CACX;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-C6B_Nm3i.d.cts","names":[],"sources":["../src/core/chunk-machine.ts","../src/core/scheduler.ts","../src/core/chunk-scheduler.ts","../src/core/deferred-task.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;KAyBY;KAGA;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