Update fakeworker.js

This commit is contained in:
Namhyeon Go 2022-10-28 01:29:25 +09:00
parent 44914f7067
commit e190b98a5e

View File

@ -57,7 +57,8 @@ function FakeWorker() {
'delay': delay,
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
'timestamp': Date.now(),
'cleared': false
'cleared': false,
'callback': null
});
return this.__lastIntervalID__;
} else {
@ -82,7 +83,21 @@ function FakeWorker() {
}
};
this.getIntervals = function() {
this.__setIntervalWithCallback__ = function(code, callback) {
this.__lastIntervalID__++;
this.__intervals__.push({
'id': this.__lastIntervalID__,
'code': code,
'delay': delay,
'arguments': [],
'timestamp': Date.now(),
'cleared': false,
'callback': callback
});
return this.__lastIntervalID__;
};
this.__getIntervals__ = function() {
var intervals = [];
var cur = Date.now();
@ -90,13 +105,16 @@ function FakeWorker() {
if (!this.__intervals__[i].cleared && (this.__intervals__[i].timestamp + this.__intervals__[i].delay) >= cur) {
intervals.push(this.__intervals__[i]);
this.__intervals__[i].timestamp = cur;
if (typeof this.__intervals__[i].callback === "function") {
this.__intervals__[i].delay = this.__intervals__[i].callback();
}
}
}
return intervals;
};
this.getTimeouts = function() {
this.__getTimeouts__ = function() {
var timeouts = [];
var cur = Date.now();