包详细信息

timers-ext

medikoo19.8mISC0.1.8

Timers extensions

timeout, delay, interval, time

自述文件

Build status Tests coverage npm version

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

MAXTIMEOUT (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/once)

Makes sure to execute fn function only once after a defined interval of time (debounce). 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

$ npm test

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

更新日志

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.1.8 (2024-06-03)

Maintenance Improvements

  • Bump dependencies (1644a83)
  • Declare minimum Node.js version (2cb991d)

0.1.7 (2018-10-04)

Bug Fixes

0.1.6 (2018-10-04)

Features

  • report timeout value on error (abb4afa)

0.1.5 (2018-03-13)

Features

0.1.4 (2018-03-08)

Bug Fixes

  • promise: clear timeout on promise resolution (6301a6b)

0.1.3 (2018-03-07)

Features

  • promise: promise.timeout method (3f52d27)

Changelog for previous versions

See CHANGES file