https://github.com/callumacrae/after-delay
:hourglass: Basically setTimeout on steroids
https://github.com/callumacrae/after-delay
Last synced: 3 months ago
JSON representation
:hourglass: Basically setTimeout on steroids
- Host: GitHub
- URL: https://github.com/callumacrae/after-delay
- Owner: callumacrae
- Created: 2015-02-17T15:11:01.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-17T15:12:35.000Z (over 10 years ago)
- Last Synced: 2025-04-01T21:07:56.277Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 117 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# after-delay [](https://travis-ci.org/callumacrae/after-delay)
after-delay runs some code once a period of time has passed with after-delay
not being called again in that time.Do you recognise this code?
```js
var timeout;on('someEvent', function () {
clearTimeout(timeout);timeout = setTimeout(function () {
console.log('Event not fired for a second!');
}, 1000);
});
```Using this library, you can write just this:
```js
var afterDelay = require('after-delay');on('someEvent', function () {
afterDelay('someEvent', function () {
console.log('Event not fired for a second!');
}, 1000);
});
```It's an entire two lines shorter!
The event name should be unique to each event, and when `afterDelay()` is
called with the same name, the old timeout will be cancelled.Calling `afterDelay()` without a function will cause the delay to be cancelled.
This behaviour is also aliased to `afterDelay.cancel()`.## Install
```
$ npm install --save after-delay
```## Usage
```js
afterDelay(eventName, callbackFunction, timeoutInMs);
afterDelay.cancel(eventName);
```## License
Released under the MIT license.