Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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.
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);
The 'node-schedule' package is a flexible cron-like and not-cron-like job scheduler for Node.js. It allows you to schedule jobs using cron syntax or by specifying a specific date. Unlike 'retimer', which focuses on resetting timers, 'node-schedule' is more suited for scheduling recurring tasks.
The 'cron' package provides a way to schedule jobs using cron syntax. It is useful for running tasks at specific intervals or times. While 'retimer' is designed for timers that can be reset, 'cron' is more focused on scheduling tasks based on time patterns.
The 'later' package is a library for describing recurring schedules and calculating future occurrences. It provides a more advanced scheduling mechanism compared to 'retimer', which is primarily focused on simple timer management.
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
npm install retimer --save
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)
Exactly like your beloved setTimeout
.
Returns a Retimer object
Reschedule the timer. Retimer will not gove any performance benefit if the specified timeout comes before the original timeout.
Clear the timer, like your beloved clearTimeout
.
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.
MIT
FAQs
Reschedulable Timer for your node needs
The npm package retimer receives a total of 284,866 weekly downloads. As such, retimer popularity was classified as popular.
We found that retimer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.