JSFiddle - React, Tailwind, and code Playground
by paska
JavaScript
function executeWithDelay(fn, delay) {
var crearTimer = function(timer) {
timer = setTimeout(fn, delay);
},
borrarTimer = function(timer) {
clearTimeout(timer);
timer = null;
},
timer = crearTimer(timer);
return {
forzarEjecucion: function() {
borrarTimer(timer);
fn();
},
reiniciarTimer: function() {
borrarTimer(timer);
crearTimer(timer);
}
};
}