1.0.2 • Published 8 years ago

loop-promise v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

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