0.39.2 • Published 5 years ago

@util.js/timers v0.39.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@util.js/timers

An object to hold JavaScript timers: https://nodejs.org/api/timers.html

@util.js/timers is part of Util.js.

Timers

timers.throttle(functionToThrottle, limitInMilliseconds) ⇒ Promise

Returns an asynchronous function that throttles the specified functionToThrottle calling it once every limitInMilliseconds.

Kind: instance method of Timers
Returns: Promise - A throttled version of functionToThrottle
Throws:

  • TypeError If functionToThrottle is not a function
  • TypeError If limitInMilliseconds is a Symbol
ParamTypeDescription
functionToThrottlefunctionThe function to wrap
limitInMillisecondsNumberThe minimum amount of time between calls to functionToThrottle; if this value cannot be coerced into a number, then 0 is assumed

Example

const timers = require("@util.js/timers");
let lastTime = Date.now();
function call(str) {
  console.log(str + ": " + (Date.now() - lastTime));
  lastTime = Date.now();
}
const throttledCall = timers.throttle(call, 2000);
throttledCall("a"); // should output "a: ~1".
throttledCall("b"); // should output "b: ~2000".
throttledCall("c"); // should output "c: ~2000".
0.39.2

5 years ago

0.39.1

5 years ago

0.39.0

5 years ago

0.38.0

5 years ago

0.37.1

5 years ago

0.37.0

5 years ago

0.36.1

5 years ago

0.36.0

5 years ago

0.35.0

5 years ago

0.34.0

5 years ago

0.33.1

5 years ago

0.33.0

5 years ago

0.32.0

5 years ago

0.31.0

5 years ago

0.30.0

5 years ago

0.29.1

5 years ago