2.0.1 • Published 3 years ago

set-alarm v2.0.1

Weekly downloads
200
License
AGPL-3.0
Repository
github
Last release
3 years ago

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

2.0.1

3 years ago

2.0.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago