Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_.delay() - killing the timer

Just curious if there is a way to kill the timer in the _.delay function in the underscore.js library. It is using setTimeout() in the annotated source but I can't figure out the actual way to do this.

An example would be:

_.delay(this.functionName, 5000)

If this has not been called at 3 seconds and I want to stop functionName being called, can I kill the timer early?

like image 800
gleddy Avatar asked Jul 17 '12 18:07

gleddy


1 Answers

var timerId = _.delay(this.functionName, 5000); //save the timerid in a variable
clearTimeout(timerId); //Kill the timer
like image 61
Esailija Avatar answered Nov 08 '22 09:11

Esailija