UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

36 lines (35 loc) • 1.05 kB
import { LiteQueuer } from "../vendor/.pnpm/@tanstack_pacer-lite@0.3.0/vendor/@tanstack/pacer-lite/dist/lite-queuer.js"; import { QueueDisposedError } from "../errors.js"; import { runWithCommitCompletion } from "./commit-completion.js"; function queueStrategy(options) { let processingChain = Promise.resolve(); let disposed = false; const queuer = new LiteQueuer(({ run, onCommit }) => { processingChain = processingChain.then(async () => { await runWithCommitCompletion(run, onCommit); }).catch(() => {}); }, { wait: options?.wait ?? 0, maxSize: options?.maxSize, addItemsTo: options?.addItemsTo ?? `back`, getItemsFrom: options?.getItemsFrom ?? `front`, started: true }); return { _type: `queue`, options, execute: (fn, _onAdmit, onCommit) => { if (disposed) throw new QueueDisposedError(); return queuer.addItem({ run: fn, onCommit }); }, cleanup: () => { disposed = true; if (queuer.isEmpty) queuer.stop(); } }; } export { queueStrategy }; //# sourceMappingURL=queueStrategy.js.map