1.0.4 • Published 8 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-queueSimple 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[]) : voidAddstaskin the end of the queue.start() : voidStarts the execution of the tasks in the queue.stop() : voidStops the execution.on(eventType : ('start' | 'stop'), callback : Function) : {cancel : Function}Adds an listener to the event specified ineventType. When the event occurscallbackwill be called. The listener is removed if the returnedcancelfunction is called.
ITaskQueueConfig
Config object for the TaskQueue.
autorun? : booleanTasks are run automatically if set totrue(no need to runstart()). Default isfalse.stoppable? : booleanTheTaskQueuecan be stopped if set totrue. Default istrue.
Contribute
Make sure to run the tests
npm test