qrun v0.0.2-beta.4
QRun
Lightweight and easy-to-use JavaScript library for managing queues efficiently.
Table of Contents
- QRun
- Table of Contents
- Installation
- Usage
- API - QRun object - createQueue() - getQueue() - getAllQueues() - stopQueue() - stopAllQueues() - Queue object - uuid - add() - finishAdding() - stop() - onDone() - onError() - whenStopped() - whenFinalised()
- Contributing
- Author
Installation
Install with npm
npm install qrunUsage
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);
});API
QRun object
createQueue()
Creates a new QRun queue.
Args:
callback(params, done, stop): A callback that will executeQRunwhile the queue is executing.options: -options.save: Enable or disable queue saving inQRunstorage. Default 'true'. The following methods of the QRun object will not work if saving is disabled.
getQueue()
Get queue by uuid.
Args:
queueUUID: queue uuid.
getAllQueues()
Get all queues.
stopQueue()
Stop queue by uuid.
stopAllQueues()
Stop all queues.
Queue object
uuid
Unique queue identifier. Required for working with QRun storage.
add()
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.
finishAdding()
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()
Stop queue.
onDone()
Listen for done() events.
Args:
callback(data): A callback that will executeQRunwhile calling the done() method in createQueue() callback.
onError()
Catching errors.
Args:
callback(error): A callback that will executeQRunduring an error.
whenStopped()
Listening for a `stop' event. It is triggered only once.
Args:
callback(): A callback that will executeQRunwhile calling the stop() method in createQueue() callback.
whenFinalised()
Listening for a `final' event. It is triggered only once.
Args:
callback(): A callback that will only executeQRunafter calling finishAdding().
Contributing
Clone repo, run npm install to install all dependencies.
Thank you for considering contributing. :)
Author
DevSnippets - @devsnippets
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago