make-github-pseudonymous-again / set-alarm

:alarm_clock: Call a Function on a given Date

Home Page:https://make-github-pseudonymous-again.github.io/set-alarm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

:alarm_clock: Call a Function on a given Date

https://make-github-pseudonymous-again.github.io/set-alarm

License:GNU Affero General Public License v3.0


Languages

Language:JavaScript 86.7%Language:Shell 13.3%