Monster.Util. DeadMansSwitch

The dead man's switch allows to set a timer which can be reset again and again within a defined period of time.

Constructor

new DeadMansSwitch(delay, callback)

Class to be able to execute function chains

Create new dead man's switch

Parameters:
NameTypeDescription
delayInteger
callbackfunction
Since
  • 1.29.0
License
  • AGPLv3
Throws:

value is not an integer

Type
TypeError
Example
import {DeadMansSwitch} from '@schukai/monster/source/util/deadmansswitch.mjs';

const deadmansswitch = new DeadMansSwitch(100, () => {
    console.log('yeah!')
    // ↦ "yeah!"
})

deadmansswitch.touch(); // from here wait again 100 ms
deadmansswitch.touch(200); // from here wait 200 ms

Methods

touch(delayopt)

Parameters:
NameTypeAttributesDescription
delayInteger | undefined<optional>