Skip to content

Commit aefa478

Browse files
committed
Avoid node TimeoutNegativeWarning
This restores the two different paths for calculating the remaining milliseconds which was removed in emscripten-core#12122. Inspired by emscripten-core#23716
1 parent 6fcf73c commit aefa478

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/lib/libeventloop.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,16 @@ LibraryJSEventLoop = {
135135
{{{ runtimeKeepalivePop() }}}
136136
callUserCallback(() => {
137137
if ({{{ makeDynCall('idp', 'cb') }}}(t, userData)) {
138+
{{{ runtimeKeepalivePush() }}}
138139
// Save a little bit of code space: modern browsers should treat
139140
// negative setTimeout as timeout of 0
140141
// (https://stackoverflow.com/questions/8430966/is-calling-settimeout-with-a-negative-delay-ok)
141-
{{{ runtimeKeepalivePush() }}}
142-
setTimeout(tick, n - _emscripten_get_now());
142+
var remaining = n - _emscripten_get_now()
143+
#if ENVIRONMENT_MAY_BE_NODE
144+
// Recent revsions of node, however, give TimeoutNegativeWarning
145+
remaining = Math.max(0, remaining);
146+
#endif
147+
setTimeout(tick, remaining);
143148
}
144149
});
145150
}

0 commit comments

Comments
 (0)