Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

FlareMind/typescript-task-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typescript-task-queue

Build Status

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 for TaskQueue.
  • enqueue(task : Function | Function[]) : void Adds task 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 in eventType. When the event occurs callback will be called. The listener is removed if the returned cancel function is called.

ITaskQueueConfig

Config object for the TaskQueue.

  • autorun? : boolean Tasks are run automatically if set to true (no need to run start()). Default is false.
  • stoppable? : boolean The TaskQueue can be stopped if set to true. Default is true.

Contribute

Make sure to run the tests

npm test

About

A class used to execute tasks in order.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published