Socket
Socket
Sign inDemoInstall

retimer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retimer

Reschedulable Timer for your node needs


Version published
Weekly downloads
175K
increased by1.13%
Maintainers
1
Weekly downloads
 
Created

Package description

What is retimer?

The 'retimer' npm package is a utility for creating and managing timers that can be reset. It is useful for scenarios where you need to repeatedly reset a timer based on certain events or conditions.

What are retimer's main functionalities?

Creating a Timer

This feature allows you to create a timer that will execute a callback function after a specified delay. In this example, the timer will log 'Timer expired' after 1000 milliseconds.

const retimer = require('retimer');

const timer = retimer(() => {
  console.log('Timer expired');
}, 1000);

Resetting a Timer

This feature allows you to reset the timer to a new delay. In this example, the timer is initially set to expire in 1000 milliseconds, but it is reset to expire in another 1000 milliseconds after 500 milliseconds have passed.

const retimer = require('retimer');

const timer = retimer(() => {
  console.log('Timer expired');
}, 1000);

// Reset the timer to expire in another 1000 milliseconds
setTimeout(() => {
  timer.reschedule(1000);
}, 500);

Clearing a Timer

This feature allows you to clear the timer before it expires. In this example, the timer is cleared after 500 milliseconds, so the 'Timer expired' message will not be logged.

const retimer = require('retimer');

const timer = retimer(() => {
  console.log('Timer expired');
}, 1000);

// Clear the timer before it expires
setTimeout(() => {
  timer.clear();
  console.log('Timer cleared');
}, 500);

Other packages similar to retimer

Readme

Source

retimer  Build Status

reschedulable setTimeout for you 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: 51867ms
  • benchRetimer*100: 34237ms

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, if the specified timeout comes after the original timeout.

Returns true if successful, false otherwise

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.

License

MIT

Keywords

FAQs

Package last updated on 09 Oct 2017

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc