
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
timeout-raf
Advanced tools
Bare-bones animation-friendly cancelable timeouts via requestAnimationFrame
Bare-bones animation-friendly cancelable timeouts via requestAnimationFrame
Provides the familiarity of setTimeout
, but via requestAnimationFrame
.
Deferred callbacks can be fired immediately or killed.
See "usage" below.
The requestAnimationFrame
approach means your callbacks will likely not fire exactly when you originally instructed.
If things are running at a smooth 60fps, callbacks should generally fire within 16ms of being told to.
Run the tests to see typical results.
Install via npm.
$ npm i timeout-raf
Require the module - it exposes a single factory function (so there's no need to instantiate instances).
Call as you would window.setTimeout
, passing a callback and duration.
var timeout = require('timeout-raf');
// typical usage; console.log is called after 1s
timeout(function () {
console.log('1 second later...');
}, 1000);
You can pass context via an optional third parameter, allowing you to define the context of the callback.
var awesomeObject = {awesome: 'clearly'};
// logs `clearly` after (about) 1 second
timeout(function () {
console.log(this.awesome);
}, 1000, awesomeObject);
You can also pass context per usual by binding the callback to any object.
var awesomeObject = {awesome: 'clearly'};
// also logs `clearly` after (about) 1 second
timeout(function () {
console.log(this.awesome);
}.bind(awesomeObject), 1000);
Keep a reference to the timeout and then call its kill()
method to prevent it from ever firing its callback.
// never writes to the console...
var to = timeout(function () {
console.log('I am never heard from again');
}, 1000);
to.kill();
You can tell a timeout to fire its callback at any time earlier than originally requested.
Keep a reference to the timeout and call its fire
method if you get antsy.
The callback will fire immediately, and never again.
// fired after 1 second and never again
var to = timeout(function () {
console.log('I could only wait a second!');
}, 2000);
timeout(function () {
to.fire();
}, 1000);
Tests can be run in-browser via npm test
.
FAQs
Bare-bones animation-friendly cancelable timeouts via requestAnimationFrame
The npm package timeout-raf receives a total of 33 weekly downloads. As such, timeout-raf popularity was classified as not popular.
We found that timeout-raf 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
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.