setAutoInterval
setAutoInterval (auto-interval) is a newer
ECMAScript
setInterval
implementation which balances cumulative timing errors.
Example with setInterval
var intervalID = setInterval(
() => console.log("The Date.now() is ", Date.now()),
100
);
setTimeout(clearInterval, 5000, intervalID); // Finish after 5s
Example with setAutoInterval
const { setAutoInterval } = require("auto-interval");
var clearAutoInterval = setAutoInterval(
() => console.log("The Date.now() is ", Date.now()),
100
);
setTimeout(clearAutoInterval, 5000); // Finish after 5s
What's the difference?
setInterval()
and setAutoInterval()
.
Comparison of gap between ETA (Expected Time) and Actual Run Time in
Time Table for setInterval()
Time Table for setAutoInterval()
Advantages
- Same function signature as
setInterval()
- Ultra-lightweight
- Minimum code adaptation
Demos and Tools
Demonstration is here.
License
Copyright (C) 2020 Lautaro Capella (twitter: @PkuyApp).