Skip to content

throttleEarly

Subhajit Sahu edited this page Aug 7, 2022 · 1 revision

Generate leading-edge throttled version of a function.

Alternatives: throttle, throttleEarly.
Similar: throttle, debounce.


function throttleEarly(x, t)
// x: a function
// t: wait time (ms)
const xasyncfn = require('extra-async-function');


var count = 0;
var fn = xasyncfn.throttleEarly(() => ++count, 2500);
setTimeout(fn, 0);
setTimeout(fn, 1000);
setTimeout(fn, 2000);
// `count` incremented after 0s


var count = 0;
var fn = xasyncfn.throttleEarly(() => ++count, 2500);
setTimeout(fn, 0);
setTimeout(fn, 1000);
setTimeout(fn, 2000);
setTimeout(fn, 3000);
setTimeout(fn, 4000);
// `count` incremented after 0s
// `count` incremented after 3s


References

Clone this wiki locally