custom-interval

0.1.0 • Public • Published

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.

Package Sidebar

Install

npm i custom-interval

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

12.9 kB

Total Files

11

Last publish

Collaborators

  • perrymitchell