Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/busterc/promise-do-whilst
:loop: Calls a function repeatedly while a condition returns true and then resolves the promise
https://github.com/busterc/promise-do-whilst
es6-promise flow-control promise promise-library promise-modules promises
Last synced: about 1 month ago
JSON representation
:loop: Calls a function repeatedly while a condition returns true and then resolves the promise
- Host: GitHub
- URL: https://github.com/busterc/promise-do-whilst
- Owner: busterc
- License: isc
- Created: 2015-11-25T22:12:37.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-25T21:47:54.000Z (over 6 years ago)
- Last Synced: 2024-08-08T15:44:07.715Z (6 months ago)
- Topics: es6-promise, flow-control, promise, promise-library, promise-modules, promises
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# promise-do-whilst [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
> Calls a function repeatedly while a condition returns true and then resolves the promise- See Also
- [promise-whilst](https://github.com/sindresorhus/promise-whilst)
- [promise-until](https://github.com/busterc/promise-until)
- [promise-do-until](https://github.com/busterc/promise-do-until)## Installation
```sh
$ npm install --save promise-do-whilst
```## Usage
```js
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]()
[npm-image]: https://badge.fury.io/js/promise-do-whilst.svg
[npm-url]: https://npmjs.org/package/promise-do-whilst
[travis-image]: https://travis-ci.org/busterc/promise-do-whilst.svg?branch=master
[travis-url]: https://travis-ci.org/busterc/promise-do-whilst
[daviddm-image]: https://david-dm.org/busterc/promise-do-whilst.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/busterc/promise-do-whilst