JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4925405
  • Score
    100M100P100Q208567F
  • License MIT

Timers extensions

Package Exports

  • timers-ext/delay
  • timers-ext/once
  • timers-ext/valid-timeout

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (timers-ext) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

timers-ext

Timers extensions

Installation

$ npm install timers-ext

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

API

MAX_TIMEOUT (timers-ext/max-timeout)

Maximum possible timeout value in milliseconds. It equals to maximum positive value for 32bit signed integer, so 2³¹ (2147483647), which makes it around 24.9 days

delay(fn[, timeout]) (timers-ext/delay)

Returns function which when invoked will call fn function after specified timeout. If timeout is not provided nextTick propagation is used.

once(fn[, timeout]) (timers-ext/timeout)

Makes sure fn function is invoked only once in given timeout span. If timeout is not provided nextTick propagation is used.

var nextTick = require('next-tick');
var logFoo = function () { console.log('foo'); };
var logFooOnce = require('timers-ext/once')(logFoo);

logFooOnce();
logFooOnce(); // ignored, logFoo will be logged only once
logFooOnce(); // ignored


nextTick(function () {
 logFooOnce(); // Invokes another log (as tick passed)
 logFooOnce(); // ignored
 logFooOnce(); // ignored
});

validTimeout(timeout) (timers-ext/valid-timeout)

Validates timeout value.
For NaN resolved timeout 0 is returned. If timeout resolves to a number:

  • for timeout < 0 0 is returned
  • for 0 >= timeout <= MAX_TIMEOUT, timeout value is returned
  • for timeout > MAX_TIMEOUT exception is thrown

Tests Build Status

$ npm test