Skip to content

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

License

Notifications You must be signed in to change notification settings

sanosay/node-promise-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages