Licence
MIT
Version
0.3.1
Deps
4
Size
17 kB
Vulns
0
Weekly
0
extra-timers
Utilities for timers.
Install
npm install --save extra-timers
# or
yarn add extra-timers
API
setTimeout
function setTimeout(
timeout: number
, callback: () => unknown
): () => void
A wrapper for globalThis.setTimeout, with the following differences:
- Better order of parameters.
- The return value is the function to cancel the timer.
- It works correctly on Node.js #26578.
- It works correctly when
timeoutisInfinity. - It works correctly when
timeoutis greater than2147483647.
setSchedule
function setSchedule(
timestamp: number
, callback: () => unknown
): () => void
A wrapper for setTimeout.
setInterval
function setInterval(
timeout: number
, callback: () => unknown
): () => void
A wrapper for setTimeout instead of globalThis.setInterval.
setImmediate
function setImmediate(
callback: () => unknown
): () => void
A wrapper for gloalThis.setImmediate and setTimeout(0, callback).
setTimeoutLoop
function setTimeoutLoop(
timeout: number
, callback: () => Awaitalbe<unknown>
): () => void
Create an interval timer using the nested setTimeout,
which does not schedule the next run until the callback function returns.
The return value is the function to cancel the timer.
setDynamicTimeoutLoop
function setDynamicTimeoutLoop(
timeout: number
, callback: () => Awaitable<unknown>
): () => void
Create an interval timer using the nested setTimeout,
which does not schedule the next run until the callback function returns,
and dynamically adjusts the interval time based on the execution time of the callback function.
The return value is the function to cancel the timer.
calculateExponentialBackoffTimeout
function calculateExponentialBackoffTimeout({
baseTimeout
, retries
, maxTimeout = Infinity
, factor = 2
, jitter = true
}: {
baseTimeout: number
retries: number
maxTimeout?: number
factor?: number
jitter?: boolean
}): number