Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jahredhope/with-cooldown
Stops calls to the supplied method happening for a cooldown period
https://github.com/jahredhope/with-cooldown
npm-package
Last synced: about 1 month ago
JSON representation
Stops calls to the supplied method happening for a cooldown period
- Host: GitHub
- URL: https://github.com/jahredhope/with-cooldown
- Owner: jahredhope
- Created: 2017-11-06T10:22:35.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-24T19:47:44.000Z (over 4 years ago)
- Last Synced: 2024-10-05T14:10:50.489Z (about 1 month ago)
- Topics: npm-package
- Language: JavaScript
- Size: 64.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# with-cooldown
[![Build Status](https://travis-ci.org/jahredhope/with-cooldown.svg?branch=master)](https://travis-ci.org/jahredhope/with-cooldown)
[![Greenkeeper badge](https://badges.greenkeeper.io/jahredhope/with-cooldown.svg)](https://greenkeeper.io/)
Stops calls to the supplied method happening for a cooldown period.
The initial call will go through, and for the timeout given all further calls will be immediately returned.Multiple calls are not replayed after the cooldown.
This module works both with and without decorators, however decorators are the primary tested use-case.
### Example
##### function syntax
```javascript
import withCooldown from './with-cooldown';const foo = withCooldown(100, () => console.log('Only call me once in 100ms'));
foo(); // => Only call me once
foo(); // immediate return
```##### decorator syntax
```javascript
class Foo {
@withCooldown(100)
bar() {
console.log('Only call me once in 100ms');
}
}const foo = new Foo();
foo.bar(); // => Only call me once
foo.bar(); // immediate return
```### Contributing
Contributions are welcome.
Pull requests will not be merged without related unit tests.