mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
timers: Move list.ontimeout to separate function
This commit is contained in:
parent
aec2f733f9
commit
ba94f9d6f8
105
lib/timers.js
105
lib/timers.js
@ -66,62 +66,67 @@ function insert(item, msecs) {
|
||||
L.init(list);
|
||||
|
||||
lists[msecs] = list;
|
||||
|
||||
list.ontimeout = function() {
|
||||
debug('timeout callback ' + msecs);
|
||||
|
||||
var now = Date.now();
|
||||
debug('now: ' + (new Date(now)));
|
||||
|
||||
var first;
|
||||
while (first = L.peek(list)) {
|
||||
var diff = now - first._idleStart;
|
||||
if (diff + 1 < msecs) {
|
||||
list.start(msecs - diff, 0);
|
||||
debug(msecs + ' list wait because diff is ' + diff);
|
||||
return;
|
||||
} else {
|
||||
L.remove(first);
|
||||
assert(first !== L.peek(list));
|
||||
|
||||
if (!first._onTimeout) continue;
|
||||
|
||||
// v0.4 compatibility: if the timer callback throws and the
|
||||
// domain or uncaughtException handler ignore the exception,
|
||||
// other timers that expire on this tick should still run.
|
||||
//
|
||||
// https://github.com/joyent/node/issues/2631
|
||||
var domain = first.domain;
|
||||
if (domain && domain._disposed) continue;
|
||||
try {
|
||||
if (domain)
|
||||
domain.enter();
|
||||
var threw = true;
|
||||
first._onTimeout();
|
||||
if (domain)
|
||||
domain.exit();
|
||||
threw = false;
|
||||
} finally {
|
||||
if (threw) {
|
||||
process.nextTick(function() {
|
||||
list.ontimeout();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug(msecs + ' list empty');
|
||||
assert(L.isEmpty(list));
|
||||
list.close();
|
||||
delete lists[msecs];
|
||||
};
|
||||
list.msecs = msecs;
|
||||
list.ontimeout = listOnTimeout;
|
||||
}
|
||||
|
||||
L.append(list, item);
|
||||
assert(!L.isEmpty(list)); // list is not empty
|
||||
}
|
||||
|
||||
function listOnTimeout() {
|
||||
var msecs = this.msecs;
|
||||
var list = this;
|
||||
|
||||
debug('timeout callback ' + msecs);
|
||||
|
||||
var now = Date.now();
|
||||
debug('now: ' + now);
|
||||
|
||||
var first;
|
||||
while (first = L.peek(list)) {
|
||||
var diff = now - first._idleStart;
|
||||
if (diff + 1 < msecs) {
|
||||
list.start(msecs - diff, 0);
|
||||
debug(msecs + ' list wait because diff is ' + diff);
|
||||
return;
|
||||
} else {
|
||||
L.remove(first);
|
||||
assert(first !== L.peek(list));
|
||||
|
||||
if (!first._onTimeout) continue;
|
||||
|
||||
// v0.4 compatibility: if the timer callback throws and the
|
||||
// domain or uncaughtException handler ignore the exception,
|
||||
// other timers that expire on this tick should still run.
|
||||
//
|
||||
// https://github.com/joyent/node/issues/2631
|
||||
var domain = first.domain;
|
||||
if (domain && domain._disposed) continue;
|
||||
try {
|
||||
if (domain)
|
||||
domain.enter();
|
||||
var threw = true;
|
||||
first._onTimeout();
|
||||
if (domain)
|
||||
domain.exit();
|
||||
threw = false;
|
||||
} finally {
|
||||
if (threw) {
|
||||
process.nextTick(function() {
|
||||
list.ontimeout();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug(msecs + ' list empty');
|
||||
assert(L.isEmpty(list));
|
||||
list.close();
|
||||
delete lists[msecs];
|
||||
}
|
||||
|
||||
|
||||
var unenroll = exports.unenroll = function(item) {
|
||||
L.remove(item);
|
||||
|
@ -3,5 +3,5 @@
|
||||
^
|
||||
ReferenceError: undefined_reference_error_maker is not defined
|
||||
at null._onTimeout (*test*message*timeout_throw.js:*:*)
|
||||
at Timer.list.ontimeout (timers.js:*:*)
|
||||
at Timer.listOnTimeout [as ontimeout] (timers.js:*:*)
|
||||
at process._makeCallback (node.js:*:*)
|
||||
|
Loading…
Reference in New Issue
Block a user