Implementated with Web Worker
import { timer } from 'az-timer';
const webWorkerTimer = timer('webworker');
const id = webWorkerTimer.setInterval(() => {...}, interval);
webWorkerTimer.clearInterval(id);
Implementated with WebAudio API.
import { timer } from 'az-timer';
let id = -1;
// oscillator timers must be started by user gestures
start.onclick = () => {
const oscTimer = timer('oscillator'); // or just timer()
id = oscTimer.setInterval(() => {...}, interval);
}
stop.onclick = () => {
oscTimer.clearInterval(id);
}
Implementated with requestAnimationFrame
import { timer } from 'az-timer';
const rafTimer = timer('raf');
const id = rafTimer.setInterval(() => {...}, interval);
rafTimer.clearInterval(id);
Implementated with window.setInterval/clearInterval/setTimeout/clearTimeout
import { timer } from 'az-timer';
const nativeTimer = timer('native');
const id = nativeTimer.setInterval(() => {...}, interval);
nativeTimer.clearInterval(id);