# extra-timers

> Utilities for timers

Latest version **0.3.1** (published 2026-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install extra-timers
pnpm add extra-timers
yarn add extra-timers
bun add extra-timers
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2026-04-21 |
| First published | 2021-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 4 |
| Unpacked size | 17.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlackGlory |
| Maintainers | black_glory |
| Keywords | setTimeout, setInterval, setImmediate, exponential, backoff |

## Links

- npm: https://www.npmjs.com/package/extra-timers
- Repository: https://github.com/BlackGlory/extra-timers
- Homepage: https://github.com/BlackGlory/extra-timers#readme
- Issues: https://github.com/BlackGlory/extra-timers/issues
- npm.io page: https://npm.io/package/extra-timers

## Dependencies (4)

- [justypes](https://npm.io/package/justypes.md) ^4.5.0
- [extra-rand](https://npm.io/package/extra-rand.md) ^0.4.1
- [extra-utils](https://npm.io/package/extra-utils.md) ^5.19.0
- [@blackglory/pass](https://npm.io/package/@blackglory/pass.md) ^1.1.1

## Recent versions

- 0.3.1 (latest) — 2026-04-21
- 0.3.0 — 2025-09-03
- 0.2.6 — 2023-06-11
- 0.2.5 — 2022-01-05
- 0.2.4 — 2021-12-12
- 0.2.3 — 2021-12-03
- 0.2.2 — 2021-09-15
- 0.2.1 — 2021-03-27
- 0.2.0 — 2021-03-13
- 0.1.0 — 2021-03-13

## README

# extra-timers
Utilities for timers.

## Install
```sh
npm install --save extra-timers
# or
yarn add extra-timers
```

## API
### setTimeout
```ts
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](https://github.com/nodejs/node/issues/26578).
- It works correctly when `timeout` is `Infinity`.
- It works correctly when `timeout` is greater than `2147483647`.

### setSchedule
```ts
function setSchedule(
  timestamp: number
, callback: () => unknown
): () => void
```

A wrapper for `setTimeout`.

### setInterval
```ts
function setInterval(
  timeout: number
, callback: () => unknown
): () => void
```

A wrapper for `setTimeout` instead of `globalThis.setInterval`.

### setImmediate
```ts
function setImmediate(
  callback: () => unknown
): () => void
```

A wrapper for `gloalThis.setImmediate` and `setTimeout(0, callback)`.

### setTimeoutLoop
```ts
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
```ts
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
```ts
function calculateExponentialBackoffTimeout({
  baseTimeout
, retries
, maxTimeout = Infinity
, factor = 2
, jitter = true
}: {
  baseTimeout: number
  retries: number
  maxTimeout?: number
  factor?: number
  jitter?: boolean
}): number
```

---
_Source: https://npm.io/package/extra-timers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
