An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Custom-Interval
> Customisable setInterval with variating delay and immediate execution (optional)

[![Build Status](https://travis-ci.org/perry-mitchell/custom-interval.svg?branch=master)](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.