1.0.4 • Published 6 years ago
typescript-task-queue v1.0.4
typescript-task-queue
A small class used to run multiple async tasks after each other.
Installation
With npm
npm install --save typescript-task-queue
Simple usage
import {TaskQueue} from 'typescript-task-queue'
let taskQueue = new TaskQueue();
// Add a function to the queue
taskQueue.enqueue(() => {
// Some async code will run here
// ...
});
// Start the queue
taskQueue.start();
// Stop the queue
taskQueue.stop();
// Callback on start
taskQueue.on('start', () => {
// ...
});
// Callback on stop
taskQueue.on('stop', () => {
// ...
});
Docs
Below follows complete information about the classes.
TaskQueue
Class that stores tasks and executes them.
TaskQueue(config? : ITaskQueueConfig)
Constructor forTaskQueue
.enqueue(task : Function | Function[]) : void
Addstask
in the end of the queue.start() : void
Starts the execution of the tasks in the queue.stop() : void
Stops the execution.on(eventType : ('start' | 'stop'), callback : Function) : {cancel : Function}
Adds an listener to the event specified ineventType
. When the event occurscallback
will be called. The listener is removed if the returnedcancel
function is called.
ITaskQueueConfig
Config object for the TaskQueue
.
autorun? : boolean
Tasks are run automatically if set totrue
(no need to runstart()
). Default isfalse
.stoppable? : boolean
TheTaskQueue
can be stopped if set totrue
. Default istrue
.
Contribute
Make sure to run the tests
npm test