mirror of
https://github.com/linuxserver/core.git
synced 2026-02-20 05:07:19 +08:00
18 lines
396 B
JavaScript
18 lines
396 B
JavaScript
/**
|
|
* Return a function that ensures callback is
|
|
* not called more often ten once per tpms (times per ms)
|
|
*/
|
|
function throttle(tpms) {
|
|
var last = Date.now();
|
|
|
|
return function(callback) {
|
|
var now = Date.now();
|
|
var delay = Math.max(0, last - now);
|
|
|
|
last = now + delay + tpms;
|
|
|
|
setTimeout(callback, delay);
|
|
};
|
|
}
|
|
|
|
module.exports = throttle; |