Socket
Socket
Sign inDemoInstall

retimer

Package Overview
Dependencies
7
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    retimer

Reschedulable Timer for your node needs


Version published
Weekly downloads
231K
increased by2.5%
Maintainers
1
Install size
481 kB
Created
Weekly downloads
 

Readme

Source

retimer  Build Status

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

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

Keywords

FAQs

Last updated on 11 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc