README
precurring - Recurring Promises
Installation
npm install --save precurring
Alternatively, the UMD build is available on unpkg:
<script src="https://unpkg.com/precurring/dist/precurring.umd.js"></script>
You can find the library on window.precurring.
Examples
Pinging a server
import precurring from 'precurring';
const ping = precurring({
fn: () => fetch('/ping'),
interval: 5000, // fetch every 5 sec
timeout: 20000, // wait 20 sec max (optional)
onSuccess: console.log,
onError: console.error
});
ping.start();
Stopping after X errors
import precurring from 'precurring';
let counter = 0;
const instance = precurring({
fn: myFunction, // make sure it returns something ".then-able"
interval: 1000,
onSuccess: console.log,
onError: () => {
if (++counter === 3) {
instance.stop();
}
}
});
instance.start();
License
MIT © Lion Ralfs