debounce function in underscore

2.5k views Asked by At

I am trying to use the debounce function for setting automatic logout for my application. My understanding is that debounce function will fire the function after the 30 seconds if my application not used. I tried to read the documentation of debounce and feel like I have done the exact something. Am i missing out something? or Is my understanding totally wrong?

var logout_debounce = _.debounce(debounceHandler, 30);
function debounceHandler() {
    location.reload();
}

$("body").on("mousemove", logout_debounce);
2

There are 2 answers

4
Dominic On BEST ANSWER

The time is in milliseconds so you would need to do 30 * 1000

0
Atlas On

That 30 is milliseconds, if you want it to be fired after 30 seconds ; you must use 30*1000 = 30000