Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coya/task-manager

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coya/task-manager

Scheduler for run tasks successively or simultaneously

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Task Manager

Scheduler for run tasks successively or simultaneously.

Installation

npm install @coya/task-manager

Build (for dev)

git clone https://github.com/Cooya/TaskManager
cd TaskManager
npm install // it will also install the development dependencies
npm run build
npm run example // run the example script in "examples" folder

Usage examples

const { TaskManager, Task } = require('@coya/task-manager');

const firstTask = new Task('firstTask', 10, function() {
    console.log('hello');
    return Promise.resolve();
});

const secondTask = new Task('secondTask', 5, function() {
    console.log('hola');
    return Promise.resolve();
});

const thirdTask = new Task('thirdTask', 2, function() {
    console.log('failure');
    return Promise.reject();
});

const taskManager = new TaskManager();
taskManager.onTaskEnd(function(task) {
    console.log('The task "' + task.name + '" has been removed from the task manager.');
});
taskManager.onEnd(function() {
    console.log('All tasks have been stopped, task manager shutted down.');
});
taskManager.processAsynchronousTasks([firstTask, secondTask, thirdTask]);

Methods

processSynchronousTasks(taskList)

Process tasks list successively, it means that tasks are executed one by one. The following task is executed once the previous one is done.

ParameterTypeDescriptionDefault value
taskListarraylist of objects implementing or inheriting the Task classnone

processAsynchronousTasks(taskList)

Process tasks list simultaneously, it means that tasks are executed in the same time (using setTimeout()). It is different from setInterval() because the timer is launched after the task has been processed.

ParameterTypeDescriptionDefault value
taskListarraylist of objects implementing or inheriting the Task classnone

Task spec

The Task class, and so its constructor, contains three fields :

  • name => name of the task
  • timeInterval => interval in seconds between each task execution
  • maxFailuresInARow (optional) => determine the number of failures in a row before the task will be taken out of the task list (default it is 5)
  • run => task function called by the scheduler, it must return a promise (this function can be passed to the Task constructor or be a member method of the inheriting class)

Keywords

FAQs

Package last updated on 04 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc