Intervals made easy
MIT License
Intervals made easy
$ npm install easy-interval
With stopping outside of interval function:
const Interval = require('easy-interval');
const interval = new Interval(() => console.log('hello world'), 1000);
interval.start();
setTimeout(interval.stop, 5000); // or `interval.stop();`
With stopping inside of interval function:
const axios = require('axios');
const Interval = require('easy-interval');
const interval = new Interval(async ({stop}) => {
try {
const {data} = await axios.get('https://store-api.io/transactions/1');
if (data.status === 'complete') {
console.log(data);
// Do stuff with `data`
stop();
}
} catch (err) {
console.error(err);
}
}, 1000);
interval.start();
Type: function
The function to set an interval on.
Type: number
The time period in milliseconds.
Interval.start()
Interval.stop()
MIT © jxom