Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
A delayed function runs some code once a period of time has passed if the delayed function is not being called again in that time.
A delayed function runs some code once a period of time has passed if the delayed function is not being called again in that time.
$ npm install --save delay-me
TypeScript
Delaying a function without recreating it (recommended way)
import {createDelayed} from 'delay-me';
const throttled_resize_handler = createDelayed(() => {
console.log(`I'm a delayed callback. I'm doing some heavy calculations when window size changes`);
});
window.addEventListener('resize', () => throttled_resize_handler.set(250));
// You can force the callback to be executed immediately
// It will cancel the previously set timeout
throttled_resize_handler.now();
// Also, you can cancel a delay
throttled_resize_handler.cancel();
Delaying tagged function in a global delaying context
With this approach, if you will use the same tag for different situations - it will lead to unexpected behavior
import {delay} from 'delay-me';
window.addEventListener('resize', () => {
const cancel = delay('throttled_resize_handler', 250, () => {
console.log(`I'm a delayed callback. I'm doing some heavy calculations when window size changes`);
});
// You can cancel delayed function execution
if(...){
cancel();
}
});
Delaying tagged function in specific context
With this approach, you can use the same tags in different contexts.
import {createDelayContext} from 'delay-me';
const delay1 = createDelayContext();
window.addEventListener('resize', () => {
const cancel = delay1('throttled_resize_handler', 250, () => {
console.log(`I'm a delayed callback. I'm doing some heavy calculations when window size changes`);
});
// You can cancel delayed function execution
if(...){
cancel();
}
});
// Somewhere else in your application
const delay2 = createDelayContext();
// Example of event
something.on('resize', () => {
const cancel = delay2('throttled_resize_handler', 250, () => {
console.log(`I'm doing some heavy calculations when something is resized`);
});
// You can cancel delayed function execution
if(...){
cancel();
}
});
Release under the MIT license
FAQs
A delayed function runs some code once a period of time has passed if the delayed function is not being called again in that time.
The npm package delay-me receives a total of 3 weekly downloads. As such, delay-me popularity was classified as not popular.
We found that delay-me 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.