# new ConcurrentCallbackQueue(options)
Creates a new concurrent callback queue.
Creates a new concurrent callback queue.
Parameters:
Name | Type | Description |
---|---|---|
options |
QueueOptions
|
Queue configuration options. |
- Version:
- 0.8.32
- Since:
- 2023-03-23
- Tutorials:
- See:
Examples
Basic usage
const queue = new ConcurrentCallbackQueue();
queue.enqueue(() => fetch('https://httpstat.us/200,400?sleep=2000'));
Custom options
const queue = new ConcurrentCallbackQueue({
autoStart: false,
onCallbackError: (error) => console.error(error),
});
queue.enqueue(() => throw new Error('Error'));
queue.start();
Multiple callbacks
const queue = new ConcurrentCallbackQueue();
queue.enqueueAll([
() => fetch('https://httpstat.us/200,400?sleep=2000'),
() => fetch('https://httpstat.us/200,400?sleep=2000'),
]);
Classes
- create
- Creates a new concurrent callback queue.
Methods
# clear() → {Array.<CallbackTuple>}
Stops the execution of the queue and removes all pending callbacks from it.
Stops the execution of the queue and removes all pending callbacks from it.
List of pending callbacks
Array.<CallbackTuple>
# dequeue() → {CallbackTuple|undefined}
Removes a pending callback from the queue without stopping execution.
Removes a pending callback from the queue without stopping execution.
Removed callback tuple or undefined if the queue is empty.
CallbackTuple
|
undefined
# dequeueAll() → {Array.<CallbackTuple>}
Removes all pending callbacks from the queue without stopping the queue execution.
Removes all pending callbacks from the queue without stopping the queue execution.
List of pending callbacks
Array.<CallbackTuple>
# enqueue(callback, retriesopt) → {void}
Adds a callback to the queue, if autoStart is enabled the queue execution starts.
Adds a callback to the queue, if autoStart is enabled the queue execution starts. You can specify an optional number of retries in case of an error.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
function
|
The callback function to add to the queue. |
||
retries |
number
|
<optional> |
0 | Number of retry attempts in case of an error (optional). |
If the callback is not a function or retries is not a number.
Error
void
# enqueueAll(callbacks, retriesopt) → {void}
Adds multiple callbacks to the queue, if autoStart is enabled the queue execution starts.
Adds multiple callbacks to the queue, if autoStart is enabled the queue execution starts. You can specify an optional number of retry attempts in case of an error.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callbacks |
Array.<function()>
|
The array of callback functions to add to the queue. |
||
retries |
number
|
<optional> |
0 | Number of retry attempts in case of an error for all callbacks (optional). |
If callbacks is not an array of functions or retries is not a number.
Error
void
# getOptions()
Returns the current queue configuration options.
Returns the current queue configuration options.
# getPendingCount() → {number}
Returns the number of pending callbacks in the queue.
Returns the number of pending callbacks in the queue.
number
# getRunningCount() → {number}
Returns the number of running callbacks in the queue.
Returns the number of running callbacks in the queue.
number
# getState() → {string}
Returns the current state of the queue.
Returns the current state of the queue.
string
# start() → {void}
Starts the execution of the queue.
Starts the execution of the queue.
If the queue is stopped at any point and then restarted, the execution resumes from the last pending callback.
void
# stop() → {void}
Stops the execution of the queue, but does not remove pending callbacks.
Stops the execution of the queue, but does not remove pending callbacks.
Calling this method will not stop the execution of callbacks that are already being processed, nor will it remove pending callbacks from the queue, so if the queue is restarted, it will resume from the last pending callback. Sets the queue state to STOPPED.
void