diff --git a/lib/ace/lib/lang.js b/lib/ace/lib/lang.js index e9585dca..6ea59761 100644 --- a/lib/ace/lib/lang.js +++ b/lib/ace/lib/lang.js @@ -134,7 +134,7 @@ exports.getMatchOffsets = function(string, regExp) { return matches; }; - +/* deprecated */ exports.deferredCall = function(fcn) { var timer = null; @@ -166,4 +166,39 @@ exports.deferredCall = function(fcn) { return deferred; }; + +exports.delayedCall = function(fcn, defaultTimeout) { + var timer = null; + var callback = function() { + timer = null; + fcn(); + }; + + var _self = function(timeout) { + timer && clearTimeout(timer); + timer = setTimeout(callback, timeout || defaultTimeout); + }; + + _self.delay = delayed; + _self.schedule = function(timeout) { + if (timer == null) + timer = setTimeout(callback, timeout || 0); + }; + + _self.call = function() { + this.cancel(); + fcn(); + }; + + _self.cancel = function() { + timer && clearTimeout(timer); + timer = null; + }; + + _self.isPending = function() { + return timer; + }; + + return _self; +}; });