
This is a collection of functions for working with intervals.
The setInterval function sets an interval to run a function every ms milliseconds. When calling setInterval with only the function and the time, the function will be used as the key.
The function passed to the setInterval function must be constant, otherwise you will not be able to clear the interval.
import { setInterval } from '@aracna/core';
function fn() {
console.log('running', Date.now());
}
setInterval(fn, 1000);The setInterval function can also be called with a custom key. This is useful when you want to clear an interval with a function that is not constant.
import { setInterval } from '@aracna/core';
const key = 'interval';
setInterval(() => console.log('running', Date.now()), 1000, key);The clearInterval function clears an interval.
import { clearInterval, setInterval } from '@aracna/core';
function fn() {
console.log('running', Date.now());
}
setInterval(fn, 1000);
setTimeout(() => clearInterval(fn), 2500);The clearEveryInterval function clears all intervals.
import { clearEveryInterval, setInterval } from '@aracna/core';
function fn() {
console.log('running', Date.now());
}
setInterval(() => console.log('running 1', Date.now()), 1000);
setInterval(() => console.log('running 2', Date.now()), 1000);
setTimeout(() => clearEveryInterval(), 2500);The isIntervalSet function checks if an interval is set.
import { isIntervalSet, setInterval } from '@aracna/core';
function fn() {
console.log('running', Date.now());
}
setInterval(fn, 1000);
// will log true
console.log(isIntervalSet(fn));