sleeptime2

Detects when the system wakes up from standby

Usage no npm install needed!

<script type="module">
  import sleeptime2 from 'https://cdn.skypack.dev/sleeptime2';
</script>

README

sleeptime2

Detects when the system wakes up from standby

(Improved version of sleeptime)

Docs

Example

const SleepTime2 = require('sleeptime2')

function onWakeUp (diff, now) {
  console.log('The system was asleep for ~%s', diff)
  console.log('Time now: %s', now)
  console.log('Time at last check: %s', now - diff)
}

const wakeUpTimer = new SleepTime2(onWakeUp)

console.log(wakeUpTimer)

API

SleepTime2(onWakeUp[, maxDiff])

  • onWakeUp: Function called if the time difference between the last check and now is bigger than maxDiff
  • maxDiff: Amount of milliseconds that the machine needs to be asleep for the event to trigger

.start()

Spawns a fork that watches the time

Automatically called after creation

.stop()

Kills the fork if any is running