Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit f45eb2d

Browse files
committed
timers: update now within listOnTimeout
Fixes #8133, #8105.
1 parent 38d5e53 commit f45eb2d

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

lib/timers.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ function listOnTimeout() {
9797

9898
debug('timeout callback %d', msecs);
9999

100-
var now = Timer.now();
101-
debug('now: %s', now);
102-
103-
var diff, first, hasQueue, threw;
100+
var now, diff, first, hasQueue, threw;
104101
while (first = L.peek(list)) {
102+
now = Timer.now();
103+
debug('now: %d', now);
105104
diff = now - first._idleStart;
105+
106106
if (diff < msecs) {
107107
list.start(msecs - diff, 0);
108108
debug('%d list wait because diff is %d', msecs, diff);

test/simple/test-timers-busy.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var common = require('../common');
23+
var assert = require('assert');
24+
25+
var DELAY = 50;
26+
var WINDOW = 5;
27+
28+
function nearly(a, b) {
29+
if (Math.abs(a-b) > WINDOW)
30+
assert.strictEqual(a, b);
31+
}
32+
33+
function work(ms) {
34+
var start = Date.now();
35+
while (Date.now() - start < ms);
36+
}
37+
38+
function test() {
39+
var start = Date.now();
40+
setTimeout(function() {
41+
work(DELAY + 20);
42+
setTimeout(function() {
43+
nearly(DELAY*3+20, Date.now() - start);
44+
}, DELAY);
45+
}, DELAY);
46+
}
47+
48+
test();

0 commit comments

Comments
 (0)