https://github.com/perry-mitchell/custom-interval
Customisable setInterval with variating delay
https://github.com/perry-mitchell/custom-interval
setinterval settimeout timer
Last synced: 4 months ago
JSON representation
Customisable setInterval with variating delay
- Host: GitHub
- URL: https://github.com/perry-mitchell/custom-interval
- Owner: perry-mitchell
- License: mit
- Created: 2018-12-10T17:34:31.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-10T20:54:14.000Z (about 7 years ago)
- Last Synced: 2025-02-15T00:03:23.236Z (about 1 year ago)
- Topics: setinterval, settimeout, timer
- Language: JavaScript
- Size: 43.9 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Custom-Interval
> Customisable setInterval with variating delay and immediate execution (optional)
[](https://travis-ci.org/perry-mitchell/custom-interval)
`npm install custom-interval --save`
## Usage
Custom-Interval provides a `setInterval`-like API to set and clear custom intervals using `setCustomInterval` and `clearCustomInterval`. These intervals can be used just like the standard `setInterval`, but also come packed with the ability to have custom-stepping on delays:
```javascript
const { clearCustomInterval, setCustomInterval } = require("custom-interval");
const interval = setCustomInterval(() => console.log("Fire!"), [
100,
150,
"2x300",
500
]);
// Later:
clearCustomInterval(interval);
```
_In this example the callback is executed at a **custom interval** where the execution times are 100, 150, 300, 300 and then 500 (repeating)._
Custom intervals can also fire on the leading edge (immediate execution, but asynchronous):
```javascript
setCustomInterval(callback, 2000, { immediate: true });
```
Check out the [API documentation](API.md) for more info.