A small library that extends the capabilities of the standard setTimeout
and setInterval
.
-
Setting timers in web worker thread. Some browsers lower the priority of timers, when switching to another tab or minimizing the window, this produce execution delay more than expected. For timers working in a separate thread, there is no such problem.
-
Counting the time difference between set timer and trigger callback
$ npm install ticle
or
<script src="https://unpkg.com/ticle@latest/build/ticle.js">
Timers in worker thread
import Ticle from 'ticle';
const WorkerTimer = new Ticle.WorkerTimer({ recordDiff: true });
WorkerTimer.setTrustyInterval(
(diff, arg1) => console.log(diff, arg1),
1000, 'arg1');
// 1001, arg1
// ...
Standard
import Ticle from 'ticle';
const WorkerTimer = new Ticle.SimpleTimer({ recordDiff: true });
WorkerTimer.setInterval(
(diff, arg1) => console.log(diff, arg1),
1000, arg1');
Some examples stored in examples/
.
WorkerTimer(options)
SimpleTimer(options)
-
setTimeout(func: Function, delay: number [, ...args]) - similar to
setTimeout
,...args
- any number of arguments provided tofunc
. -
setInterval(func: Function, delay: number [, ...args]) - similar to
setInterval
. -
setTrustyInterval(func: Function, delay: number [, ...args]) - similar to
setInterval
, realisation base onsetTimeout
. -
clearTimeout(id: number) - similar to
learTimeout
. -
clearInterval(id: number) - similar to
clearInterval
. -
clearTrustyInterval(id: number) - similar to
clearTimeout
, but forsetTrustyInterval
.
- recordDiff: boolean - whether to record time difference between set timer and trigger callback. The result is passed as the 1st argument to the callback.