Timers extensions


$ 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

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

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

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(); // ignored, logFoo will be logged only once 
logFooOnce(); // ignored 
nextTick(function () {
 logFooOnce(); // Invokes another log (as tick passed) 
 logFooOnce(); // ignored 
 logFooOnce(); // ignored 

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


$ npm test