watchdog

Watchdog v0.1.13 Documentation

Classes

Watchdog

Typedefs

WatchdogEvent

Watchdog Class Event Type

WatchdogListener

Watchdog Class Event Function

WatchdogFood

Dog Feed content

Watchdog

Kind: global class

new Watchdog([defaultTimeout], [name])

A Timer used to detect and recover from malfunctions

Param Type Default
[defaultTimeout] number 60 * 1000
[name] string "'Bark'"

Example

const TIMEOUT = 1 * 1000  // 1 second
const dog = new watchdog(TIMEOUT)

const food = { data: 'delicious' }

dog.on('reset', () => console.log('reset-ed'))
dog.on('feed',  () => console.log('feed-ed'))

dog.feed(food)
// Output: feed-ed

setTimeout(function() {
  dog.sleep()
  console.log('dog sleep-ed. Demo over.')
}, TIMEOUT + 1)
// Output: reset-ed.
// Output: dog sleep-ed. Demo over.

watchdog.on(event, listener) ⇒ this

Kind: instance method of Watchdog

Param Type
event WatchdogEvent
listener WatchdogListener.<T, D>

Example (Event:reset )

dog.on('reset', () => console.log('reset-ed'))

Example (Event:feed )

dog.on('feed',  () => console.log('feed-ed'))

Example (Event:sleep )

dog.on('sleep',  () => console.log('sleep-ed'))

watchdog.left() ⇒ number

Get the left time

Kind: instance method of Watchdog

watchdog.feed(food) ⇒ number

feed the dog

Kind: instance method of Watchdog

Param Type
food WatchdogFood

Example

const food = {
  data:    'delicious',
  timeout: 1 * 1000,
}
const dog = new Watchdog()
dog.feed(food)

watchdog.sleep()

Clear timer.

Kind: instance method of Watchdog
Example

const dog = new Watchdog()
dog.sleep()

WatchdogEvent

Watchdog Class Event Type

Kind: global typedef
Properties

Name Type Description
feed string Emit when feed the dog.
reset string Emit when timeout and reset.
sleep string Emit when timer is cleared out.

WatchdogListener

Watchdog Class Event Function

Kind: global typedef
Properties

Type Description
function (food: WatchdogFood<T, D>, left: number) => void

WatchdogFood

Dog Feed content

Kind: global typedef
Properties

Name Type Description
data D feed content.
timeout number option, set timeout.
type T option.