https://github.com/make-github-pseudonymous-again/set-alarm
:alarm_clock: Call a Function on a given Date
https://github.com/make-github-pseudonymous-again/set-alarm
Last synced: 22 days ago
JSON representation
:alarm_clock: Call a Function on a given Date
- Host: GitHub
- URL: https://github.com/make-github-pseudonymous-again/set-alarm
- Owner: make-github-pseudonymous-again
- License: agpl-3.0
- Created: 2021-02-18T08:45:02.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-14T10:35:12.000Z (over 1 year ago)
- Last Synced: 2024-04-14T12:01:42.044Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://make-github-pseudonymous-again.github.io/set-alarm
- Size: 2 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
:alarm_clock: [set-alarm](https://make-github-pseudonymous-again.github.io/set-alarm)
==
Call a `Function` on a given `Date`.
The API tries to mimic [the `setTimeout` API](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout) as best as possible.
See [docs](https://make-github-pseudonymous-again.github.io/set-alarm/index.html).
```js
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
```
[](https://raw.githubusercontent.com/make-github-pseudonymous-again/set-alarm/main/LICENSE)
[](https://www.npmjs.org/package/set-alarm)
[](https://github.com/make-github-pseudonymous-again/set-alarm/actions/workflows/ci.yml?query=branch:main)
[](https://github.com/make-github-pseudonymous-again/set-alarm/network/dependencies)
[](https://github.com/make-github-pseudonymous-again/set-alarm/issues)
[](https://www.npmjs.org/package/set-alarm)
[](https://codeclimate.com/github/make-github-pseudonymous-again/set-alarm/issues)
[](https://codeclimate.com/github/make-github-pseudonymous-again/set-alarm/trends/churn)
[](https://codecov.io/gh/make-github-pseudonymous-again/set-alarm)
[](https://codeclimate.com/github/make-github-pseudonymous-again/set-alarm/trends/technical_debt)
[](https://make-github-pseudonymous-again.github.io/set-alarm/source.html)
[](https://bundlephobia.com/result?p=set-alarm)