New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

whiletrue

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

whiletrue

Start/stop/pause/repeat: task runner in Javascript

latest
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

whiletrue

Start/stop/pause/repeat: task runner in Javascript

Usage

Given the following iteration condition...

//Condition: iterate 10 times
function condition(state){

    //In 'state.index' is contained iteration 
    //number '0-based'
    return state.index < 10;
}

and the following task to run, over and over...

//Task: do some work, then invoke "done"
function longTask(done, state){

    //Do some stuff here...
    console.log("Doing some stuff...");
    
    //Argument "state" => ex: { 
    //  iterations: 5,  //Current iteration number 
    //  delay: 10       //Delay (in ms) between iterations
    //}

    setTimeout(function(){

        //Task completed: remember to invoke ALWAYS "done"
        console.log("Task completed!");
        done();

    }, 1000);
}

just setup the "whiletrue" runner (with 10 millisecond of delay between each iteration)...

//Setup: Create a "whiletrue" runner with 10 ms delay
var runner = whiletrue(condition, longTask, 10);

start the execution and handle the promise of "job completed"...

//Start execution
runner.run()
    .then(function(){
        console.log("Job completed");
    });

...or start the execution in parallel mode...

//Start execution
runner.runParallel()
    .then(function(){
        console.log("Job completed");
    });

Keywords

linq

FAQs

Package last updated on 07 Sep 2015

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