# @jil/retimer

> A reschedulable setTimeout library for JavaScript

Latest version **0.2.0** (published 2023-12-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jil/retimer
pnpm add @jil/retimer
yarn add @jil/retimer
bun add @jil/retimer
```

## Health

**Score 25/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2023-12-30 |
| First published | 2022-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 0 |
| Unpacked size | 11.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | TY |
| Maintainers | towyuan |

## Links

- npm: https://www.npmjs.com/package/@jil/retimer
- npm.io page: https://npm.io/package/@jil/retimer

## Recent versions

- 0.2.0 (latest) — 2023-12-30
- 0.1.25 — 2023-10-18
- 0.1.24 — 2023-06-09
- 0.1.23 — 2023-03-19
- 0.1.22 — 2023-02-08
- 0.1.21 — 2022-12-29
- 0.1.20 — 2022-12-23
- 0.1.19 — 2022-10-25
- 0.1.18 — 2022-09-20
- 0.1.17 — 2022-03-03
- 0.1.16 — 2022-02-27
- 0.1.15 — 2022-02-15
- 0.1.14 — 2022-02-13
- 0.1.13 — 2022-02-10
- 0.1.12 — 2022-02-05
- … 11 more at https://npm.io/package/@jil/retimer/versions

## README

# @jil/retimer

> A reschedulable setTimeout library for JavaScript. This library is built for building a keep alive functionality
> across a large numbers of clients/sockets.
>
> Forked from [retimer](https://github.com/mcollina/retimer)

## Install

```
npm install @jil/retimer --save
```

## Example

```ts
import {retimer} from '@jil/retimer';

const timer = retimer(() => {
  throw new Error('this should never get called!');
}, 20);

setTimeout(() => {
  timer.reschedule(50);
  setTimeout(() => {
    timer.clear();
  }, 10);
}, 10);
```

## API

### retimer(runner, timeout, ...args)

Exactly like your beloved `setTimeout`. Returns a `Retimer object`

### timer.reschedule(timeout)

Reschedule the timer. Retimer will not gove any performance benefit if the specified timeout comes **before** the
original timeout.

### timer.clear()

Clear the timer, like your beloved `clearTimeout`.

## How it works

Timers are stored in a Linked List in node.js, if you create a lot of timers this Linked List becomes massive which
makes **removing a timer an expensive operation**. Retimer let the old timer run at its time, and schedule a new one
accordingly, when the new one is **after** the original timeout. There is no performance gain when the new timeout is
before the original one as retimer will just **remove the previous timer**.

## License

MIT

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