Skip to content

About

🌲 Utilities for timers.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

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 timeout is Infinity.
  • It works correctly when timeout is greater than 2147483647.

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

About

🌲 Utilities for timers.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages