Skip to content

Commit ec0266a

Browse files
committed
Update libev's clock when starting timers
Make the timeouts more accurate. See test/pummel/test-timers.js
1 parent b72ffc0 commit ec0266a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/node_timer.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ Timer::Start (const Arguments& args)
120120
ev_tstamp repeat = NODE_V8_UNIXTIME(args[1]);
121121
ev_timer_init(&timer->watcher_, Timer::OnTimeout, after, repeat);
122122
timer->watcher_.data = timer;
123+
124+
// Update the event loop time. Need to call this because processing JS can
125+
// take non-negligible amounts of time.
126+
ev_now_update(EV_DEFAULT_UC);
127+
123128
ev_timer_start(EV_DEFAULT_UC_ &timer->watcher_);
124129

125130
if (!was_active) timer->Ref();

0 commit comments

Comments
 (0)