function createAsyncQueuer<TValue, TSelected>(
fn,
options,
selector): SolidAsyncQueuer<TValue, TSelected>;
function createAsyncQueuer<TValue, TSelected>(
fn,
options,
selector): SolidAsyncQueuer<TValue, TSelected>;
Defined in: solid-pacer/src/async-queuer/createAsyncQueuer.ts:150
Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.
Features:
Tasks are processed concurrently up to the configured concurrency limit. When a task completes, the next pending task is processed if the concurrency limit allows.
Error Handling:
The hook uses TanStack Store for reactive state management. You can subscribe to state changes in two ways:
1. Using queuer.Subscribe component (Recommended for component tree subscriptions)
Use the Subscribe component to subscribe to state changes deep in your component tree without needing to pass a selector to the hook. This is ideal when you want to subscribe to state in child components.
2. Using the selector parameter (For hook-level subscriptions)
The selector parameter allows you to specify which state changes will trigger reactive updates at the hook level, 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 or using the Subscribe component. This prevents unnecessary updates and gives you full control over when your component tracks state changes.
Available state properties:
Example usage:
// Default behavior - no reactive state subscriptions
const asyncQueuer = createAsyncQueuer(async (item) => {
// process item
return await fetchData(item);
}, {
initialItems: [],
concurrency: 2,
maxSize: 100,
started: false,
onSuccess: (result) => {
console.log('Item processed:', result);
},
onError: (error) => {
console.error('Processing failed:', error);
}
});
// Opt-in to track queue state changes (optimized for UI updates)
const asyncQueuer = createAsyncQueuer(
async (item) => await fetchData(item),
{ concurrency: 2, started: true },
(state) => ({
pendingItems: state.pendingItems,
activeItems: state.activeItems,
isRunning: state.isRunning
})
);
// Opt-in to track processing metrics changes (optimized for tracking progress)
const asyncQueuer = createAsyncQueuer(
async (item) => await fetchData(item),
{ concurrency: 2, started: true },
(state) => ({
successCount: state.successCount,
errorCount: state.errorCount,
settleCount: state.settleCount
})
);
// Add items to queue
asyncQueuer.addItem(newItem);
// Start processing
asyncQueuer.start();
// Access the selected state (will be empty object {} unless selector provided)
const { pendingItems, activeItems } = asyncQueuer.state();
// Default behavior - no reactive state subscriptions
const asyncQueuer = createAsyncQueuer(async (item) => {
// process item
return await fetchData(item);
}, {
initialItems: [],
concurrency: 2,
maxSize: 100,
started: false,
onSuccess: (result) => {
console.log('Item processed:', result);
},
onError: (error) => {
console.error('Processing failed:', error);
}
});
// Opt-in to track queue state changes (optimized for UI updates)
const asyncQueuer = createAsyncQueuer(
async (item) => await fetchData(item),
{ concurrency: 2, started: true },
(state) => ({
pendingItems: state.pendingItems,
activeItems: state.activeItems,
isRunning: state.isRunning
})
);
// Opt-in to track processing metrics changes (optimized for tracking progress)
const asyncQueuer = createAsyncQueuer(
async (item) => await fetchData(item),
{ concurrency: 2, started: true },
(state) => ({
successCount: state.successCount,
errorCount: state.errorCount,
settleCount: state.settleCount
})
);
// Add items to queue
asyncQueuer.addItem(newItem);
// Start processing
asyncQueuer.start();
// Access the selected state (will be empty object {} unless selector provided)
const { pendingItems, activeItems } = asyncQueuer.state();
TValue
TSelected = { }
(value) => Promise<any>
AsyncQueuerOptions<TValue> = {}
(state) => TSelected
SolidAsyncQueuer<TValue, TSelected>