@util.js/node-timers

0.41.3 • Public • Published

@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

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
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

Example

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".

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @util.js/node-timers

    Weekly Downloads

    0

    Version

    0.41.3

    License

    MIT

    Unpacked Size

    16.1 kB

    Total Files

    11

    Last publish

    Collaborators

    • creemama