This commit is contained in:
2021-12-16 13:04:32 +03:00
parent b94cb967a6
commit 636cd65c78
21 changed files with 342 additions and 57 deletions
+15 -3
View File
@@ -11,6 +11,7 @@ __PluginManager__.register('dataStructures', function(module, exports, require,
this.timeout = 0;
this.arguments = null;
this.context = null;
this.executeBeforeTimeout = false;
this.setContext(context);
this.setCallback(callback);
this.setTimeout(timeout);
@@ -29,22 +30,33 @@ __PluginManager__.register('dataStructures', function(module, exports, require,
this.counter++;
if(this.timerId === 0) {
this.__exec(this.counter);
if(this.executeBeforeTimeout) {
this.__execBeforeTimeout(this.counter);
} else {
this.__execAfterDelay();
}
}
};
stack.prototype.__exec = function (counter) {
stack.prototype.__execBeforeTimeout = function (counter) {
this.timerId = setTimeout((function(){
if(this.counter > counter) {
this.__exec(this.counter);
this.__execBeforeTimeout(this.counter);
return null;
}
this.timerId = 0;
}).bind(this), this.timeout);
this.callback.apply(this.context, this.arguments);
};
stack.prototype.__execAfterDelay = function () {
this.timerId = setTimeout((function(){
this.callback.apply(this.context, this.arguments);
this.timerId = 0;
}).bind(this), this.timeout);
};
stack.prototype.reset = function () {
clearTimeout(this.timerId);
this.timerId = 0;
this.counter = 0;
};
return stack;
})()