Skip to content

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

License

Notifications You must be signed in to change notification settings

busterc/promise-until

Repository files navigation

promise-until NPM version Build Status Dependency Status

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

Installation

$ npm install --save promise-until

Usage

import promiseUntil from 'promise-until';

let count = 0;

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

// ...

let max = 0;

promiseUntil(() => {
  return max === 0;
}, () => {
  max++;
}).then(() => {
  console.log(max);
  // => 0
});

API

promiseUntil(condition, action)

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

condition

Type: function

Should return a boolean of whether to continue.

action

Type: function

Action to run for each iteration.

You can return a promise and it will be handled.

License

ISC © Buster Collings

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published