<commit_before># p-whilst [![Build Status](https://travis-ci.org/sindresorhus/p-whilst.svg?branch=master)](https://travis-ci.org/sindresorhus/p-whilst)

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


## Install

```
$ npm install --save p-whilst
```


## Usage

```js
const pWhilst = require('p-whilst');

let count = 0;

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


## API

### pWhilst(condition, action)

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.

#### condition

Type: `Function`

Expected to 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.


## Related

- [p-wait-for](https://github.com/sindresorhus/p-wait-for) - Wait for a condition to be true
- [More…](https://github.com/sindresorhus/promise-fun)


## License

MIT © [<NAME>](https://sindresorhus.com)<commit_msg>add related module to readme<commit_after># p-whilst [![Build Status](https://travis-ci.org/sindresorhus/p-whilst.svg?branch=master)](https://travis-ci.org/sindresorhus/p-whilst)

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


## Install

```
$ npm install --save p-whilst
```


## Usage

```js
const pWhilst = require('p-whilst');

let count = 0;

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


## API

### pWhilst(condition, action)

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.

#### condition

Type: `Function`

Expected to 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.


## Related

- [p-forever](https://github.com/sindresorhus/p-forever) - Run promise-returning & async functions repeatedly until you end it
- [p-wait-for](https://github.com/sindresorhus/p-wait-for) - Wait for a condition to be true
- [More…](https://github.com/sindresorhus/promise-fun)


## License

MIT © [<NAME>](https://sindresorhus.com)
{'fraction_non_alphanumeric': 0.1565362198168193, 'fraction_numerical': 0.002497918401332223, 'mean_word_length': 4.091101694915254, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3451027', 'n_tokens_mistral': 831, 'n_tokens_neox': 799, 'n_words': 241}