Skip to content

A super tiny library to manage timers in JavaScript

License

Notifications You must be signed in to change notification settings

cd/interval-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

interval-handler

A super tiny library to manage timers in JavaScript

Demo

🔥 https://codepen.io/chrdiede/pen/eYYjpwX 🔥

Getting started

CDN Import

<script src="https://cdn.jsdelivr.net/gh/cd/interval-handler/interval-handler.min.js"></script>

Quick Start

First, you have to create an instance:

// Create instance
var myTimers = new IntervalHandler();

Now add timers to the instance:

// First argument: Reference of the function
// Second argument (optional): Interval in milliseconds
// Further arguments will be passed as function arguments
myTimers.setTimer(console.log, 2000, "Hello from console");

If there is no valid second argument, the default interval applies. You can set the default interval like this:

IntervalHandler.interval = 3000; // milliseconds

Timers can be easily overwritten:

// Function will only be executed in 2 seconds
myTimers.setTimer(myFnc, 1000);
myTimers.setTimer(myFnc, 2000);

Clear timer like this:

// Clear a specific timer
myTimers.clearTimer(myFnc);

// Clear all timers
myTimers.clearTimer();

About

A super tiny library to manage timers in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published