2.0.2 • Published 2 years ago

no-drift v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

no-drift

Reduced drift timeouts and intervals for node.js

Inspired by driftless

Usage

// 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

Formulas for timeout times:

r = rate

t = total time

Time left

recurrence relation

d0 = t

dn = (1 - r)dn-1

closed form

dn = t(1 - r)n

Current time

recurrence relation

c0 = 0

cn = (1 - r)cn-1 + tr

closed form

cn = t(1 - (1 - r)n)

Current wait time

recurrence relation

w0 = tr

wn = (1 - r)wn-1

closed form

wn = tr(1 - r)n

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago