Skip to content

Commit 8acf577

Browse files
trop[bot]codebytere
authored andcommitted
fix: override the timers module impls to activate the uv loop (electron#18968)
1 parent 52c76fc commit 8acf577

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/common/init.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ function wrap (func, wrapper) {
3030

3131
process.nextTick = wrapWithActivateUvLoop(process.nextTick)
3232

33-
global.setImmediate = wrapWithActivateUvLoop(timers.setImmediate)
33+
global.setImmediate = timers.setImmediate = wrapWithActivateUvLoop(timers.setImmediate)
3434
global.clearImmediate = timers.clearImmediate
3535

36+
// setTimeout needs to update the polling timeout of the event loop, when
37+
// called under Chromium's event loop the node's event loop won't get a chance
38+
// to update the timeout, so we have to force the node's event loop to
39+
// recalculate the timeout in browser process.
40+
timers.setTimeout = wrapWithActivateUvLoop(timers.setTimeout)
41+
timers.setInterval = wrapWithActivateUvLoop(timers.setInterval)
42+
43+
// Only override the global setTimeout/setInterval impls in the browser process
3644
if (process.type === 'browser') {
37-
// setTimeout needs to update the polling timeout of the event loop, when
38-
// called under Chromium's event loop the node's event loop won't get a chance
39-
// to update the timeout, so we have to force the node's event loop to
40-
// recalculate the timeout in browser process.
41-
global.setTimeout = wrapWithActivateUvLoop(timers.setTimeout)
42-
global.setInterval = wrapWithActivateUvLoop(timers.setInterval)
45+
global.setTimeout = timers.setTimeout
46+
global.setInterval = timers.setInterval
4347
}
4448

4549
if (process.platform === 'win32') {

0 commit comments

Comments
 (0)