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

Usage no npm install needed!

<script type="module">
  import utilJsNodeTimers from 'https://cdn.skypack.dev/@util.js/node-timers';



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

NPM Status Travis CI Build Status

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


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

  • TypeError If functionToThrottle is not a function
  • TypeError If limitInMilliseconds is a Symbol
Param Type Description
functionToThrottle function The function to wrap
limitInMilliseconds Number The minimum amount of time between calls to functionToThrottle; if this value cannot be coerced into a number, then 0 is assumed


const timers = require("@util.js/node-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".