node-promise-scheduler

1.0.0 • Public • Published

node-promise-scheduler

A basic promise scheduler that enables parallel promise execution with a load threshold

Example usage:

"use strict";
// array that holds our Task objects
var tasks = [];
var taskCount = 100;
// create 100 Tasks
for(let i = 0;i < taskCount;i++){
    tasks.push(
      // create a new Task and push it into our array
      new Task(function(res,rej){
        setTimeout(function(){
            console.log(i);
            res(true);
        },1000*Math.random());
      })
    );
}
// create a new Scheduler 
var scheduler = new Scheduler({
  // task array that holds all of our tasks
  tasks:tasks,
  // the max load that we want to use
  maxLoad:2, 
  // fires when a task starts
  onTaskStart: function(task){
    console.log('Current load '+scheduler.getCurrentLoad());
  }
});
// start the execution of our tasks
scheduler.execute();

Package Sidebar

Install

npm i node-promise-scheduler

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • sanosay