function createQueuer<TValue>(fn, initialOptions): SolidQueuer<TValue>
function createQueuer<TValue>(fn, initialOptions): SolidQueuer<TValue>
Defined in: queuer/createQueuer.ts:108
Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
Features:
The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with stop() and start().
By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.
Example usage:
// Example with Solid signals and scheduling
const [items, setItems] = createSignal([]);
const queue = createQueuer(
(item) => {
// process item synchronously
console.log('Processing', item);
},
{
started: true, // Start processing immediately
wait: 1000, // Process one item every second
onItemsChange: (queue) => setItems(queue.peekAllItems()),
getPriority: (item) => item.priority // Process higher priority items first
}
);
// Add items to process - they'll be handled automatically
queue.addItem('task1');
queue.addItem('task2');
// Control the scheduler
queue.stop(); // Pause processing
queue.start(); // Resume processing
// Access queue state via signals
console.log('Items:', queue.allItems());
console.log('Size:', queue.size());
console.log('Is empty:', queue.isEmpty());
console.log('Is running:', queue.isRunning());
console.log('Next item:', queue.nextItem());
// Example with Solid signals and scheduling
const [items, setItems] = createSignal([]);
const queue = createQueuer(
(item) => {
// process item synchronously
console.log('Processing', item);
},
{
started: true, // Start processing immediately
wait: 1000, // Process one item every second
onItemsChange: (queue) => setItems(queue.peekAllItems()),
getPriority: (item) => item.priority // Process higher priority items first
}
);
// Add items to process - they'll be handled automatically
queue.addItem('task1');
queue.addItem('task2');
// Control the scheduler
queue.stop(); // Pause processing
queue.start(); // Resume processing
// Access queue state via signals
console.log('Items:', queue.allItems());
console.log('Size:', queue.size());
console.log('Is empty:', queue.isEmpty());
console.log('Is running:', queue.isRunning());
console.log('Next item:', queue.nextItem());
• TValue
(item) => void
QueuerOptions<TValue> = {}
SolidQueuer<TValue>
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.