Skip to content

WezomAgency/create-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

createTimer

license types

Creating timers with internal closure


Usage

import createTimer from 'create-timer';

const timer = createTimer(500);
$(window).on('resize', function () {
    timer(() => {
        console.log('done');
    });
});

// ...delay for current calling
timer(() => {
    console.log('just test after 2seconds');
}, 2000);

// ...clear timer if need
timer.clear();

API

createTimer([defaultDelay = 300])

  • @param {number} defaultDelay - default delay for created timer;
  • @returns {Function} timer
const timer1 = createTimer();
const timer2 = createTimer(600);

timer(fn[, customDelay])

  • @param {Function} fn - callback, executed after timout;
  • @param {number} [delay=defaultDelay] - delay for override with current calling
  • @returns {number} timeoutId - id of current timeout

timer.clear()

  • clear current timeout

Releases

No releases published

Packages

No packages published