promise-do-whilst
Calls a function repeatedly while a condition returns true and then resolves the promise
Last updated 10 years ago by buster .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install promise-do-whilst 
SYNC missed versions from official npm registry.

promise-do-whilst NPM version Build Status Dependency Status

Calls a function repeatedly while a condition returns true and then resolves the promise

Installation

$ npm install --save promise-do-whilst

Usage

import promiseDoWhilst from 'promise-do-whilst';

let count = 0;

promiseDoWhilst(() => {
  count++;
}, () => {
  return count < 5;
}).then(() => {
  console.log(count);
  // => 5
});

// ...

let max = 0;

promiseDoWhilst(() => {
  max++;
}, () => {
  return max < 1;
}).then(() => {
  console.log(max);
  // => 1
});

API

promiseDoWhilst(action, condition)

Executes action repeatedly while condition returns true and then resolves the promise. Rejects if action returns a promise that rejects or if an error is thrown anywhere.

action

Type: function

Action to run for each iteration.

You can return a promise and it will be handled.

condition

Type: function

Should return a boolean of whether to continue.

License

ISC © Buster Collings

Current Tags

  • 1.0.1                                ...           latest (10 years ago)

2 Versions

  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (11)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |