0.2.0 • Published 4 months ago

@jil/retimer v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

@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

Install

npm install @jil/retimer --save

Example

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

0.2.0

4 months ago

0.1.25

7 months ago

0.1.24

11 months ago

0.1.23

1 year ago

0.1.22

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago