Skip to content
Calls a function repeatedly until a condition returns true and then resolves the promise
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.babelrc
.editorconfig
.eslintrc
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
gulpfile.js
package.json

README.md

promise-do-until NPM version Build Status Dependency Status

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

Installation

$ npm install --save promise-do-until

Usage

import promiseDoUntil from 'promise-do-until';

let count = 0;

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

// ...

let max = 0;

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

API

promiseDoUntil(action, condition)

Executes action repeatedly until 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

You can’t perform that action at this time.