https://github.com/renddslow/tta
Re-run a function until it passes a condition.
https://github.com/renddslow/tta
Last synced: 2 months ago
JSON representation
Re-run a function until it passes a condition.
- Host: GitHub
- URL: https://github.com/renddslow/tta
- Owner: Renddslow
- Created: 2020-03-04T22:35:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T06:48:11.000Z (about 3 years ago)
- Last Synced: 2025-02-24T02:40:33.134Z (3 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/tta
- Size: 419 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tta
> If at first you don't succeed, try try again.
Run a function continually until it returns `true`.
## Install
```
$ yarn add tta
```## Usage
```js
import tta from 'tta';import fileExists from './fileExists';
import writeFile from './writeFile';tta(async () => !(await fileExists('.lock.json')), { wait: '3s' }).then(() => {
writeFile('some-file.txt', '🦄');
});
```## API
### tta(condition, options)
#### condition
Type: `object`
| Param | Default | Description |
| -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| wait | `500ms` | The amount of time to wait between each check on the condition. |
| maxDepth | `25` | By default tta will only repeat the conditional function call 25 times before bailing out and returning a rejected promise. You can increase this number if you're so bold. |