DeadMansSwitch

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.

You can create an instance via the monster namespace Monster.Util.DeadMansSwitch().

<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/monster.js';
new Monster.Util.DeadMansSwitch()
</script>

Alternatively, you can also integrate this class individually.

<script type="module">
import {DeadMansSwitch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/util/deadmansswitch.js';
new DeadMansSwitch();
</script>

Constructor

# new DeadMansSwitch(delay, callback)

Class to be able to execute function chains

Create new dead man's switch

Parameters:
Name Type Description
delay Integer
callback function
Since:
  • 1.29.0
Throws:

value is not an integer

Type
TypeError
Example
import {DeadMansSwitch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.30.0/dist/modules/util/deadmansswitch.js';

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:
Name Type Attributes Description
delay Integer | undefined <optional>