本页还没有译文
本页 27 段还没译成Español,下面显示的是英文原文。createQueuedSignal
还没翻译译自英文(tanstack.com)本页 27 段都还没译
function createQueuedSignal<TValue, TSelected>(
fn,
options?,
selector?): [() => TValue[], (item, position?, runOnItemsChange?) => boolean, SolidQueuer<TValue, TSelected>];Defined in: queuer/createQueuedSignal.ts:120
A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality. This primitive provides both the current queue state and queue control methods.
The queue state is automatically updated whenever items are added, removed, or reordered in the queue. All queue operations are reflected in the state array returned by the primitive.
The queue can be started and stopped to automatically process items at a specified interval, making it useful as a scheduler. When started, it will process one item per tick, with an optional wait time between ticks.
The primitive returns a tuple containing:
- The current queue state as an array
- The queue instance with methods for queue manipulation
State Management and Selector
The primitive uses Solid's reactive state management via the underlying queuer instance.
The selector parameter allows you to specify which queuer state changes will trigger reactive updates,
optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
By default, there will be no reactive state subscriptions and you must opt-in to state tracking by providing a selector function. This prevents unnecessary updates and gives you full control over when your component tracks state changes. Only when you provide a selector will the component track changes to the selected state values.
Available queuer state properties:
executionCount: Number of items that have been processed by the queuerexpirationCount: Number of items that have been removed due to expirationisEmpty: Whether the queuer has no items to processisFull: Whether the queuer has reached its maximum capacityisIdle: Whether the queuer is not currently processing any itemsisRunning: Whether the queuer is active and will process items automaticallyitems: Array of items currently waiting to be processeditemTimestamps: Timestamps when items were added for expiration trackingpendingTick: Whether the queuer has a pending timeout for processing the next itemrejectionCount: Number of items that have been rejected from being addedsize: Number of items currently in the queuestatus: Current processing status ('idle' | 'running' | 'stopped')
Type Parameters
TValue
TValue
TSelected
TSelected extends Pick<QueuerState<TValue>, "items"> = Pick<QueuerState<TValue>, "items">
Parameters
fn
(item) => void
options?
SolidPacerOptions<SolidQueuerOptions<TValue, TSelected>> = {}
selector?
(state) => TSelected
Returns
[() => TValue[], (item, position?, runOnItemsChange?) => boolean, SolidQueuer<TValue, TSelected>]
Example
// Default behavior - no reactive state subscriptions
const [items, addItem, queue] = createQueuedSignal(
(item) => console.log('Processing:', item),
{
initialItems: ['item1', 'item2'],
started: true,
wait: 1000,
getPriority: (item) => item.priority
}
);
// Opt-in to track queue contents changes (optimized for displaying queue items)
const [items, addItem, queue] = createQueuedSignal(
(item) => console.log('Processing:', item),
{ started: true, wait: 1000 },
(state) => ({
items: state.items,
size: state.size,
isEmpty: state.isEmpty
})
);
// Opt-in to track processing state changes (optimized for loading indicators)
const [items, addItem, queue] = createQueuedSignal(
(item) => console.log('Processing:', item),
{ started: true, wait: 1000 },
(state) => ({
isRunning: state.isRunning,
isIdle: state.isIdle,
status: state.status,
pendingTick: state.pendingTick
})
);
// Opt-in to track execution metrics changes (optimized for stats display)
const [items, addItem, queue] = createQueuedSignal(
(item) => console.log('Processing:', item),
{ started: true, wait: 1000 },
(state) => ({
executionCount: state.executionCount,
expirationCount: state.expirationCount,
rejectionCount: state.rejectionCount
})
);
// Add items to queue
const handleAdd = (item) => {
addItem(item);
};
// Start automatic processing
const startProcessing = () => {
queue.start();
};
// Stop automatic processing
const stopProcessing = () => {
queue.stop();
};
// Manual processing still available
const handleProcess = () => {
const nextItem = queue.getNextItem();
if (nextItem) {
processItem(nextItem);
}
};
// Access the selected queuer state (will be empty object {} unless selector provided)
const { size, isRunning, executionCount } = queue.state;