mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 21:51:04 +00:00
Update fakeworker.js
This commit is contained in:
parent
9e3b4c1327
commit
44914f7067
|
@ -27,7 +27,7 @@ function FakeWorker() {
|
||||||
if (!this.__isWindow__) {
|
if (!this.__isWindow__) {
|
||||||
for (var i = 0; i < this.__intervals__.length; i++) {
|
for (var i = 0; i < this.__intervals__.length; i++) {
|
||||||
if (this.__intervals__[i].id == intervalID) {
|
if (this.__intervals__[i].id == intervalID) {
|
||||||
delete this.__intervals__[i];
|
this.__intervals__[i].cleared = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,7 @@ function FakeWorker() {
|
||||||
if (!this.__isWindow__) {
|
if (!this.__isWindow__) {
|
||||||
for (var i = 0; i < this.__timeouts__.length; i++) {
|
for (var i = 0; i < this.__timeouts__.length; i++) {
|
||||||
if (this.__timeouts__[i].id == timeoutID) {
|
if (this.__timeouts__[i].id == timeoutID) {
|
||||||
delete this.__timeouts__[i];
|
this.__timeouts__[i].cleared = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,7 +56,8 @@ function FakeWorker() {
|
||||||
'code': code,
|
'code': code,
|
||||||
'delay': delay,
|
'delay': delay,
|
||||||
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
||||||
'timestamp': Date.now()
|
'timestamp': Date.now(),
|
||||||
|
'cleared': false
|
||||||
});
|
});
|
||||||
return this.__lastIntervalID__;
|
return this.__lastIntervalID__;
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,13 +73,42 @@ function FakeWorker() {
|
||||||
'code': code,
|
'code': code,
|
||||||
'delay': delay,
|
'delay': delay,
|
||||||
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
||||||
'timestamp': Date.now()
|
'timestamp': Date.now(),
|
||||||
|
'cleared': false
|
||||||
});
|
});
|
||||||
return this.__lastTimeoutID__;
|
return this.__lastTimeoutID__;
|
||||||
} else {
|
} else {
|
||||||
return window.setTimeout.apply(null, arguments);
|
return window.setTimeout.apply(null, arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getIntervals = function() {
|
||||||
|
var intervals = [];
|
||||||
|
var cur = Date.now();
|
||||||
|
|
||||||
|
for (var i = 0; i < this.__intervals__.length; i++) {
|
||||||
|
if (!this.__intervals__[i].cleared && (this.__intervals__[i].timestamp + this.__intervals__[i].delay) >= cur) {
|
||||||
|
intervals.push(this.__intervals__[i]);
|
||||||
|
this.__intervals__[i].timestamp = cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return intervals;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getTimeouts = function() {
|
||||||
|
var timeouts = [];
|
||||||
|
var cur = Date.now();
|
||||||
|
|
||||||
|
for (var i = 0; i < this.__timeouts__.length; i++) {
|
||||||
|
if (!this.__timeouts__[i].cleared && (this.__timeouts__[i].timestamp + this.__timeouts__[i].delay) >= cur) {
|
||||||
|
timeouts.push(this.__timeouts__[i]);
|
||||||
|
this.__timeouts__[i].cleared = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return timeouts;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.create = function() {
|
exports.create = function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user