# retimer

> Reschedulable Timer for your node needs

Latest version **4.0.0** (published 2023-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install retimer
pnpm add retimer
yarn add retimer
bun add retimer
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-08-11 |
| First published | 2015-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Matteo Collina |
| Maintainers | matteo.collina |
| Keywords | schedulable, reschedulable, timer, setTimeout |

## Links

- npm: https://www.npmjs.com/package/retimer
- Repository: https://github.com/mcollina/retimer
- Homepage: https://github.com/mcollina/retimer#readme
- Issues: https://github.com/mcollina/retimer/issues
- npm.io page: https://npm.io/package/retimer

## Dependencies (1)

- [worker-timers](https://npm.io/package/worker-timers.md) ^7.0.75

## Recent versions

- 4.0.0 (latest) — 2023-08-11
- 3.0.0 — 2021-03-02
- 2.0.0 — 2018-12-13
- 1.1.0 — 2017-10-09
- 1.0.1 — 2015-07-11
- 1.0.0 — 2015-07-11
- 0.0.1 — 2015-07-08

## README

# retimer&nbsp;&nbsp;[![Build Status](https://travis-ci.org/mcollina/retimer.png)](https://travis-ci.org/mcollina/retimer)

reschedulable setTimeout for your node needs. This library is built for
building a keep alive functionality across a large numbers of
clients/sockets.

Rescheduling a 10000 functions 20 times with an interval of 50ms (see
`bench.js`), with 100 repetitions:

* `benchSetTimeout*100: 40.295s`
* `benchRetimer*100: 36.122s`


## Install

```
npm install retimer --save
```

## Example

```js
var retimer = require('retimer')
var timer = retimer(function () {
  throw new Error('this should never get called!')
}, 20)

setTimeout(function () {
  timer.reschedule(50)
  setTimeout(function () {
    timer.clear()
  }, 10)
}, 10)
```

## API

### retimer(callback, 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/retimer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
