auto-interval
v1.0.3
Published
A newer, timing-error-free version of setInterval()
Downloads
15
Maintainers
Readme
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?
Comparison of gap between ETA (Expected Time) and Actual Run Time in setInterval()
and setAutoInterval()
.
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).