
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
setinterval
Advanced tools
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]
We all know the drawbacks of the built-in setInterval
in Node.js(actually js itself).
It's more reasonable to start measuring period after every async task gets done. So here it is.
$ npm i setinterval
const Timer = require('setinterval');
const t = new Timer(async () => {
const user = await db.User.get(id);
console.log(user);
}, 1000);
// start timer
t.setInterval();
// after some time...
// clear timer
t.clearInterval();
Timer constructor.
Params:
period
. Should be a Promise or async function or generator function or thunk.Start timer after a certain delay(defaults to 0) and can decide if invoke immediately(defaults to false).
Params:
Stop timer(can be restart again).
Triggered each time fn is finished, whenever a error is thrown. You can cancel the timer in this event. A count
parameter is passed in the event handler which stands for how many times fn has been called.
timer.on('tick', count => {
timer.clearInterval();
});
Triggered when error thrown from fn.
timer.on('error', e => {
logger.info(e.stack);
});
MIT
FAQs
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]
The npm package setinterval receives a total of 769 weekly downloads. As such, setinterval popularity was classified as not popular.
We found that setinterval 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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.