
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Precision JavaScript timer for recurring events
Adds a global object mbTimer, which can be used in place of setTimeout and setInterval in need of more precise and self-correcting recurring timer events.
Simply load the script into your page (<script src='/path/to/mb-timer.min.js></script> or using Require or any other method).
Timers can be created by calling the constructor, which takes two parameters: the duration in milliseconds between executions, and the function to execute after each delay.
var mytimer = new mbTimer(100, function() {
console.log('Do stuff here');
});
The timer will need to be started by calling mytimer.start() (This will return your timer instance)
The timer can be stopped by calling mytimer.stop() (This will return your timer instance)
The timer may also be paused for a duration, and will resume automatically when that time is over.
// Pause me for 2 seconds!
mytimer.pause(2000);
Debug mode can be enabled by passing true as the first parameter to the start function, eg: mytimer.start(true) will output metrics to the console.
Plain JS timers (setTimeout, setInterval) are relatively inaccurate. The browser takes the given duration as a 'recommendation', and will wait at least that long. Meaning that the following may happen 500, 504, or 2043 milliseconds after it is called.
setTimeout(function() {
console.log('What day is it?!')
}, 500);
mbTimer works by registering its own setTimeout calls, and giving it a wrapped version of the user-submitted execution function. Each time the wrapper function is called, it will measure the elapsed time using the Date object, and register a new setTimeout with a reduced / increased duration to counteract any inaccuracies in the setTimeout function.
Three metrics are provided in debug mode: delta, offset, and drift.
delta is the real time elapsed between executions (using the Date object)offset is the difference between the delta and the timer's registered delaydrift is the accumulated difference between the current time, and the expected time after the current number of executionsIdeally, both offset and drift will equal 0. Due to the nature of things, that will rarely be the case. Much more often, they will both be less than 5 milliseconds. That is still far, far better than setInterval can accomplish.
The plugin has not yet been rigorously tested, but should work in all modern browsers, given the browser window has focus.
NOTICE: Some browsers will reduce the importance of timer events if the browser window loses focus! This means that if a user clicks out of your browser window, events may not happen at the correct time until the window is focused again. At that time, the mbTimer will work to catch up for lost time.
Author: Matthew Balmer
Twitter: @mattbalmer
Website: http://mattbalmer.com
License: MIT
FAQs
Precision JavaScript timer for recurring events.
We found that mb-timer 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.