watchout
watchout
is a JavaScript watchdog timer with a very simple API.
Install
$ npm install watchout
Examples
Basic usage
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 = // Timeout in 5000. Execute the callback with the results, whether timeout occurred or not.var watchdog = 5000 { if haltedTimeout console else console }
Cancelling
A timer can be cancelled. Doing so will not execute the callback.
var watchout = var watchdog = 5000 { console} watchdog
Reset
A timer can be reset, or extended.
var watchout = var watchdog = 5000 { console} // 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.watchdog
Executing the callback right away
A timer can execute the callback right away with pass
or fail
methods. pass
will execute the callback with a true
, while fail
will execute the callback with a false
.
var watchout = var watchdogPass = 5000 { if haltedTimeout console } watchdogPass var watchdogFail = 5000 { if !haltedTimeout console } watchdogFail