
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
async-debounce-jt
Advanced tools
Guard against calling an asynchronous method multiple times whilst the asynchronous operation is in progress.
Guard against calling an asynchronous function multiple times whilst the asynchronous operation is in progress. Once the operation is complete, the last call made to the function whilst the operation was in progress is made.
Intermediate calls are lost, if no calls are made whilst the asynchronous operation is in progress the function is not called again.
This debounce is not based on time, it's based on a callback which is made once the operation is completed.
npm install async-debounce
var debounce = require('async-debounce');
var guarded = debounce(function (args, callback) {
// do something with the arguments, then call the callback
});
guarded('hello', 'world'); // Parameters are combined in args parameter in the function
This example calls our method every 10th of a second, but it takes 1 second to complete. The result is the guarded method is only called 10 times.
var debounce = require('async-debounce');
var dostuff = debounce(function (args, callback) {
setTimeout(function () {
console.log('Called with: ', args[0]);
callback();
}, 1000);
});
var i = 0;
var interval = setInterval(function () {
dostuff(i);
i+=1;
}, 100);
setTimeout(function () {
clearInterval(interval);
}, 10000)
Called with: 0
Called with: 9
Called with: 20
Called with: 30
Called with: 40
Called with: 50
Called with: 60
Called with: 70
Called with: 80
Called with: 90
Called with: 98
FAQs
Guard against calling an asynchronous method multiple times whilst the asynchronous operation is in progress.
We found that async-debounce-jt 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.