While a condition returns true, calls a function repeatedly, and then resolves the promise
npm install p-whilst> While a condition returns true, calls a function repeatedly, and then resolves the promise
Think async version of the while statement.
``sh`
npm install p-whilst
`js
import pWhilst from 'p-whilst';
let count = 0;
await pWhilst(
() => count < 5,
() => count++
);
console.log(count);
//=> 5
`
While condition returns true, executes action repeatedly, and then resolves the promise to the result of the last call to action. Rejects if action returns a promise that rejects or if an error is thrown anywhere.
#### condition
Type: Functionaction
Arguments: The value the function returns or initialValue for the first iteration.
Expected to return a boolean or a Promise that indicates whether to execute action.
#### action
Type: Functionaction` function returns.
Arguments: The value the last call to
Action to run for each iteration.
You can return a promise and it will be handled.
- p-do-whilst - Calls a function repeatedly while a condition returns true and then resolves the promise
- p-forever - Run promise-returning & async functions repeatedly until you end it
- p-wait-for - Wait for a condition to be true
- More…