set-alarm

2.0.1 • Public • Published

set-alarm

Call a Function on a given Date. The API tries to mimic the setTimeout API as best as possible. See docs.

import {
	setAlarm,
	clearAlarm,
	Alarm
} from 'set-alarm';

const firstOfApril2021AtNoonZuluTime = new Date('2021-04-01T12:00Z');

// Set an alarm
const alarm = setAlarm(() => {
	console.debug(new Date() - firstOfApril2021AtNoonZuluTime);
}, firstOfApril2021AtNoonZuluTime);

alarm instanceof Alarm; // true

// Two scenarios:
//  - if date is in the future: should trigger at or just after the date, logging a small nonnegative number
//  - if date is in the past: will trigger anyway logging a possibly large positive number
// It is up to you to ignore alarms for past dates (similar to `setTimeout(..., -2389324)`).

// OR Unenroll the callback (and the alarm will not trigger)
clearAlarm(alarm); // undefined

License Version Tests Dependencies Dev dependencies GitHub issues Downloads

Code issues Code maintainability Code coverage (cov) Code technical debt Documentation Package size

Package Sidebar

Install

npm i set-alarm

Weekly Downloads

5

Version

2.0.1

License

AGPL-3.0

Unpacked Size

537 kB

Total Files

16

Last publish

Collaborators

  • aureooms