Lightweight and easy-to-use JavaScript library for managing queues efficiently.
Install with npm
npm install qrun
JavaScript
import { qrun } from 'qrun';
const queue = qrun.createQueue((params, done, stop) => {
if (params === 5) {
throw new Error('error 5');
}
if (params === 7) {
return stop();
}
done(params);
});
for (let i = 0; i < 10; i++) {
queue.add(i, { cooldown: 100 });
}
queue.finishAdding(); // optional
queue.onDone(console.log);
queue.onError(console.error);
queue.whenFinalised(() => console.log('end'));
queue.whenStopped(() => console.log('stopped'));
console.log(qrun.getAllQueues());
console.log(qrun.getQueue(queue.uuid));
TypeScript
import { qrun } from 'qrun';
const queue = qrun.createQueue<number, number, Error>((params, done, stop) => {
if (params === 5) {
throw new Error('error 5');
}
if (params === 7) {
return stop();
}
done(params);
});
Creates a new QRun queue.
Args:
-
callback(params, done, stop)
: A callback that will executeQRun
while the queue is executing. -
options
:-
options.save
: Enable or disable queue saving inQRun
storage. Default 'true'. The following methods of the QRun object will not work if saving is disabled.
-
Get queue by uuid.
Args:
-
queueUUID
: queue uuid.
Get all queues.
Stop queue by uuid.
Stop all queues.
Unique queue identifier. Required for working with QRun
storage.
Adding parameters to perform a queue callback.
Args:
-
params
: Any data. String, Object, etc. -
options
:-
options.cooldown
: Setting an artificial delay in milliseconds for queue execution. Optional.
-
Finish adding parameters. After calling this method, you can no longer add new parameters. When the execution of the last added parameter is complete, the whenFinalised() callback will be triggered.
Stop queue.
Listen for done()
events.
Args:
-
callback(data)
: A callback that will executeQRun
while calling the done() method in createQueue() callback.
Catching errors.
Args:
-
callback(error)
: A callback that will executeQRun
during an error.
Listening for a `stop' event. It is triggered only once.
Args:
-
callback()
: A callback that will executeQRun
while calling the stop() method in createQueue() callback.
Listening for a `final' event. It is triggered only once.
Args:
-
callback()
: A callback that will only executeQRun
after calling finishAdding().
Clone repo, run npm install to install all dependencies.
Thank you for considering contributing. :)
DevSnippets - @devsnippets