Skip to content

Run infinite loops with promises. Cancellation enabled if using Bluebird.

License

Notifications You must be signed in to change notification settings

virtkick/loop-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loop-promise

Run infinite loops with promises. Cancellation enabled if using Bluebird.

Usage

  • Plain node
require('loop-promise')(Promise, {addMethod: true});

let loopPromise = Promise.loop(() => doSomethingThatReturnsPromise(), 100);
// running interval will be timeToRunLoopBody + 100ms

loopPromise.catch(err => {
  console.error('Loop failed with error', err);
});

// if Promise comes from bluebird and cancellation is enabled then you can also cancel the loop
// otherwise cancelling could done manually by throwing a pre-defined error and catching it outside
loopPromise.cancel();

You can also pass values through loop iterations

Promise.loop(val => val + 1, 100, 0); // 0 is the initial value passed to the loop body

About

Run infinite loops with promises. Cancellation enabled if using Bluebird.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published