Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sokratisvidros/poll-until
A promised based timed poller
https://github.com/sokratisvidros/poll-until
Last synced: 2 months ago
JSON representation
A promised based timed poller
- Host: GitHub
- URL: https://github.com/sokratisvidros/poll-until
- Owner: SokratisVidros
- License: mit
- Created: 2016-09-20T07:47:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-21T15:10:12.000Z (about 7 years ago)
- Last Synced: 2024-10-05T02:25:54.533Z (3 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# poll-until
[![](https://travis-ci.org/SokratisVidros/poll-until.svg?branch=master)](https://travis-ci.org/SokratisVidros/poll-until)
[![](https://badge.fury.io/js/pollUntil.svg)](https://www.npmjs.com/package/pollUntil)A promised based time bomb poller.
`pollUntil(fn, args = [], timeout = 3000, pollInterval = 200)`
# Usage
Start polling for the provided polling function `fn` using this promised based `pollUntil`.As soon as the poller starts, a time bomb promise is also triggered. If the polling function is satisfied before the time bomb detonates, `pollUntil` results `true` to the promise chain. Otherwise, it returns `false`.
The library works with Typescript, ES6 and ES5.
## Examples
```
import pollUntil from 'pollUntil';let counter1 = 0;
const timer = setInterval(() => {
counter ++
}, 100);// Polling succeeded before the time bomb
pollUntil((c) => c > 10, counter, 3000, 200)
.then((result) => {
clearInterval(timer1);
// result === true
// ...
});// Time bomb detonated
pollUntil((c) => c > 10, counter, 100, 200)
.then((result) => {
clearInterval(timer);
// result === false
// ...
});```
For more examples, please have a look at project's tests.
# License
The MIT License (MIT)