https://github.com/doowb/alarm
Set an alarm that will call the given function at the specified time.
https://github.com/doowb/alarm
nexttick schedule scheduler setimmediate settimeout timeout timer
Last synced: about 2 months ago
JSON representation
Set an alarm that will call the given function at the specified time.
- Host: GitHub
- URL: https://github.com/doowb/alarm
- Owner: doowb
- License: mit
- Created: 2017-05-02T18:20:46.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-11T03:15:28.000Z (almost 8 years ago)
- Last Synced: 2024-10-10T17:22:46.410Z (7 months ago)
- Topics: nexttick, schedule, scheduler, setimmediate, settimeout, timeout, timer
- Language: JavaScript
- Homepage: https://doowb.com
- Size: 10.7 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# alarm [](https://www.npmjs.com/package/alarm) [](https://npmjs.org/package/alarm) [](https://npmjs.org/package/alarm) [](https://travis-ci.org/doowb/alarm)
> Set an alarm that will call the given function at the specified time.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save alarm
```Install with [yarn](https://yarnpkg.com):
```sh
$ yarn add alarm
```## Usage
```js
var alarm = require('alarm');
```## API
### [alarm](index.js#L21)
Set an alarm that will execute the provided function at the specified time.
**Params**
* `date` **{Date}**: a Date object or a string that can be passed to the Date constructor.
* `fn` **{Function}**: Function to execute at the specified time.
* `returns` **{Function}**: Returns a function that can be called to cancel the alarm.**Example**
```js
// 2 seconds from now
var now = new Date();
var date = new Date(+now + 2000);
alarm(date, function() {
console.log('Hello, world!');
});
```### [.recurring](index.js#L53)
Set a recurring alarm that will execute the provide function even X milliseconds.
**Params**
* `ms` **{Number}**: Number of milliseconds to specify how often to execute the function.
* `fn` **{Function}**: Function to execute every X milliseconds.
* `returns` **{Function}**: Returns a function that may be called to cancel the recurring alarm.**Example**
```js
var count = 0;
var cancel = alarm.recurring(1000, function() {
console.log((count++) + ' BEEP BEEP BEEP!');
if (count >= 5) {
cancel();
}
});
```## About
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```### Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```### Author
**Brian Woodward**
* [github/doowb](https://github.com/doowb)
* [twitter/doowb](https://twitter.com/doowb)### License
Copyright © 2017, [Brian Woodward](https://doowb.com).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 10, 2017._