Home Manual Reference Source

Function

Static Public Summary
public

clearAlarm(alarm: Alarm)

Prevents an alarm from triggering.

public

setAlarm(callback: Function, date: Date, rest: ...any): Alarm

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:

NameTypeAttributeDescription
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:

  1. the delay parameter is a 32-bit signed integer
  2. taking the first point into account, the resolution time of setAlarm could be imprecise with large delays (because of setInterval/setTimeout drift).

Params:

NameTypeAttributeDescription
callback Function

The Function to call when the alarm triggers.

date Date

The date/time at which to trigger the alarm.

rest ...any

The arguments to call the callback with.

Return:

Alarm

The alarm object.