UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

42 lines (41 loc) • 1.3 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const liteQueuer = require("@tanstack/pacer-lite/lite-queuer"); const errors = require("../errors.cjs"); const commitCompletion = require("./commit-completion.cjs"); function queueStrategy(options) { let processingChain = Promise.resolve(); let disposed = false; const queuer = new liteQueuer.LiteQueuer( ({ run, onCommit }) => { processingChain = processingChain.then(async () => { await commitCompletion.runWithCommitCompletion(run, onCommit); }).catch(() => { }); }, { wait: options?.wait ?? 0, maxSize: options?.maxSize, addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front started: true // Start processing immediately } ); return { _type: `queue`, options, execute: (fn, _onAdmit, onCommit) => { if (disposed) throw new errors.QueueDisposedError(); return queuer.addItem({ run: fn, onCommit }); }, cleanup: () => { disposed = true; if (queuer.isEmpty) queuer.stop(); } }; } exports.queueStrategy = queueStrategy; //# sourceMappingURL=queueStrategy.cjs.map