File | Date | Author | Commit |
---|---|---|---|
src | 2022-03-24 | TelevisionNinja | [7a4ed9] organized the functions better |
.gitignore | 2021-03-15 | TelevisionNinja | [cbd807] Initial commit |
LICENSE | 2021-03-15 | TelevisionNinja | [cbd807] Initial commit |
README.md | 2021-12-11 | TelevisionNinja | [f10ebf] esm |
package.json | 2022-03-23 | TelevisionNinja | [e8ad57] changed interval threshold to recursion |
Reduced drift timeouts and intervals for node.js
Inspired by driftless
// import any implementation you want
import {
// default implementation
setNoDriftInterval,
setNoDriftTimeout,
clearNoDrift,
// setImmediate implementation
setNoDriftZeroInterval,
setNoDriftZeroTimeout,
clearNoDriftZero,
// worker thread implementation
setNoDriftWorkerInterval,
setNoDriftWorkerTimeout,
clearNoDriftWorker
} from 'no-drift';
//------------------
// similar usage to setTimeout and setInterval
// all implementations have the same usage
setNoDriftTimeout(() => {
console.log('Hello world 1');
});
setNoDriftTimeout(() => {
console.log('Hello world 2');
}, 1000);
setNoDriftTimeout((a, b, c) => {
console.log(a, b, c);
}, 2000, '1', '2', '3');
setNoDriftTimeout("console.log('Hello world 3');", 3000);
// nodrift intervals have the same usage shown above
//------------------
// clearing nodrift
const id = setNoDriftTimeout(() => {
console.log('clear');
}, 1000);
clearNoDrift(id);
// each implementation has their own pool of IDs
// so import and use the appropriate clearing function
r = rate
t = total time
recurrence relation
d0 = t
dn = (1 - r)dn-1
closed form
dn = t(1 - r)n
recurrence relation
c0 = 0
cn = (1 - r)cn-1 + tr
closed form
cn = t(1 - (1 - r)n)
recurrence relation
w0 = tr
wn = (1 - r)wn-1
closed form
wn = tr(1 - r)n