Created
October 25, 2018 15:55
-
-
Save renancaraujo/f04aa87db58ad545b24eaddcdc5c3ad0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** only executes the last callback sent of a unique id**/ | |
const finalTimeout = (function() { | |
const timers = {}; | |
return function(callback, ms, uniqueId) { | |
if (!uniqueId) { | |
uniqueId = 'default'; | |
} | |
if (timers[uniqueId]) { | |
window.clearTimeout(timers[uniqueId]); | |
} | |
timers[uniqueId] = setTimeout(() => { | |
delete timers[uniqueId]; | |
callback(); | |
}, ms); | |
}; | |
})(); |
EnKaizer
commented
Oct 25, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment