$ npm install watchout
An instance is created. Once the timeout occurs, the callback is executed with a
haltedTimeout, a boolean signifying whether the timer was cancelled or timeout occurred. In this example, the timeout occurred.
var watchout = require'watchout'// Timeout in 5000. Execute the callback with the results, whether timeout occurred or not.var watchdog = 5000if haltedTimeoutconsole.log'Timeout did not occur.'elseconsole.log'Timeout occurred after 5000ms.'
A timer can be cancelled. Doing so will not execute the callback.
var watchout = require'watchout'var watchdog = 5000console.log'I should never execute.'watchdogcancel
A timer can be reset, or extended.
var watchout = require'watchout'var watchdog = 5000console.log'I should execute much later.'// Assume that 4000ms has passed, now we want to reset the timer, which will extend the time by another 5000ms, extending a timer to a total of 9000ms.watchdogreset
A timer can execute the callback right away with
pass will execute the callback with a
fail will execute the callback with a
var watchout = require'watchout'var watchdogPass = 5000if haltedTimeoutconsole.log'Timer did not timeout.'watchdogPasspassvar watchdogFail = 5000if !haltedTimeoutconsole.log'Timeout occurred or was forced to timeout.'watchdogFailfail