Watchdog Class Event Type
Watchdog Class Event Function
Dog Feed content
Kind: global class
thisnumbernumberA 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.
thisKind: 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'))
numberGet the left time
Kind: instance method of Watchdog
numberfeed 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)
Clear timer.
Kind: instance method of Watchdog
Example
const dog = new Watchdog()
dog.sleep()
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. |
Watchdog Class Event Function
Kind: global typedef
Properties
| Type | Description |
|---|---|
function |
(food: WatchdogFood<T, D>, left: number) => void |
Dog Feed content
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| data | D |
feed content. |
| timeout | number |
option, set timeout. |
| type | T |
option. |