asap-es
a queue runner with priorities, concurrency and promises
installation
npm install asap-es
why
The main goal is to provide lightweight and modern library for queuing tasks. The name was inspired by the asap library. There is already a few libraries with similar functionality, yet this is another one.
lib | async | sync | concurrency | priority | size | license |
---|---|---|---|---|---|---|
✔️ | ✔️ | ✔️ | ✔️ | |||
✖️ | ✔️ | ✖️ | ✖️ | |||
✔️ | ✔️ | ✖️ | ✖️ | |||
✔️ | ✔️ | ✔️ | ✖️ | |||
✔️ | ✔️ | ✖️ | ✖️ | |||
✔️ | ✔️ | ✔️ | ✔️ | |||
✔️ | ✔️ | ✔️ | ✔️ |
api
name | description |
---|---|
new <ctor>(c) |
create new asap-es instance, optinal concurrency can be passed as argument |
<ctor>(c) |
same as above |
<instance>.c |
the number of tasks to run simultaneously (1 by default), set to < 1 to pause the queue |
<instance>.q(task, priority) |
enqueue a new task, returns a promise which resolves or rejects when execution of the task is finished, optionally pass priority |
task | task is a function which may return a value or a promise (task awaits for promise completion) |
usage example
;;;// you can have many independent queues;// paused queue will not run tasks;// resume the queue by increasing concurrencyqueuePaused.c++;// promisesqueue.qPromise.resolve2.thenconsole.log;// console >> 2// pause the queuequeue.c = 0;// async functionsqueue.q;// task with higher priorityqueue.qvoid 0, -1;// set concurrency and resume the queuequeue.c = 2;// delay execution of a task by 20 msqueue.qdelay20,void 0;// handle errorsqueue.q.catchconsole.error;// console >> error// timeout a task after given timequeue.qtimeout200,;// combine delay and timeoutqueue.qdelay10, timeout5,