0.1.0 • Published 5 years ago

custom-interval v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Custom-Interval

Customisable setInterval with variating delay and immediate execution (optional)

Build Status

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:

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):

setCustomInterval(callback, 2000, { immediate: true });

Check out the API documentation for more info.