| id | injectAsyncQueuedSignal |
|---|---|
| title | injectAsyncQueuedSignal |
function injectAsyncQueuedSignal<TValue, TSelected>(
fn,
options,
selector): AsyncQueuedSignal<TValue, TSelected>;Defined in: angular-pacer/src/async-queuer/injectAsyncQueuedSignal.ts:52
An Angular function that creates an async queuer with managed state, combining Angular's signals with async queuing functionality. This function provides both the current queue state and queue control methods.
The queue state is automatically updated whenever items are added, removed, or processed in the queue. All queue operations are reflected in the state array returned by the function.
The function returns a callable object:
queued(): Get the current queue items as an arrayqueued.addItem(...): Add an item to the queuequeued.queue: The queuer instance with additional control methods
TValue
TSelected extends Pick<AsyncQueuerState<TValue>, "items"> = Pick<AsyncQueuerState<TValue>, "items">
(value) => Promise<any>
AsyncQueuerOptions<TValue> = {}
(state) => TSelected
AsyncQueuedSignal<TValue, TSelected>
// Default behavior - track items
const queued = injectAsyncQueuedSignal(
async (item) => {
const response = await fetch('/api/process', {
method: 'POST',
body: JSON.stringify(item)
});
return response.json();
},
{ concurrency: 2, wait: 1000 }
);
// Add items
queued.addItem(data1);
// Access items
console.log(queued()); // [data1, ...]
// Control the queue
queued.queuer.start();
queued.queuer.stop();