Function
Static Public Summary | ||
public |
clearAlarm(alarm: Alarm) Prevents an alarm from triggering. |
|
public |
Set an alarm to trigger at a given date/time specified by a Date object. |
Static Public
public clearAlarm(alarm: Alarm) source
import clearAlarm from 'set-alarm/src/clearAlarm.js'
Prevents an alarm from triggering. Obviously, this does not work if the
alarm has triggered before calling clearAlarm
. However, it is guaranteed
that if clearAlarm
is called before alarm
has triggered, alarm
will
never trigger.
Does nothing on invalid arguments (it will not throw).
Params:
Name | Type | Attribute | Description |
alarm | Alarm | The alarm to clear. |
public setAlarm(callback: Function, date: Date, rest: ...any): Alarm source
import setAlarm from 'set-alarm/src/setAlarm.js'
Set an alarm to trigger at a given date/time specified by a Date object. When triggered, the alarm will call the callback function with passed arguments, if any.
We guarantee that the alarm will not trigger before the given date/time. We try to trigger the alarm as soom as the given date/time has passed.
Note that we workaround two issues raised by a naive setTimeout implementation:
- the delay parameter is a 32-bit signed integer
- taking the first point into account, the resolution time of setAlarm could be imprecise with large delays (because of setInterval/setTimeout drift).