From 1a753d0f3e3357e5c624a89e9b2592937f70159b Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 24 Jun 2019 14:40:50 -0700 Subject: [PATCH] fix: override the timers module impls to activate the uv loop --- lib/common/init.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/common/init.js b/lib/common/init.js index a69d9627e0ea8..b5036448a0c02 100644 --- a/lib/common/init.js +++ b/lib/common/init.js @@ -30,16 +30,20 @@ function wrap (func, wrapper) { process.nextTick = wrapWithActivateUvLoop(process.nextTick) -global.setImmediate = wrapWithActivateUvLoop(timers.setImmediate) +global.setImmediate = timers.setImmediate = wrapWithActivateUvLoop(timers.setImmediate) global.clearImmediate = timers.clearImmediate +// setTimeout needs to update the polling timeout of the event loop, when +// called under Chromium's event loop the node's event loop won't get a chance +// to update the timeout, so we have to force the node's event loop to +// recalculate the timeout in browser process. +timers.setTimeout = wrapWithActivateUvLoop(timers.setTimeout) +timers.setInterval = wrapWithActivateUvLoop(timers.setInterval) + +// Only override the global setTimeout/setInterval impls in the browser process if (process.type === 'browser') { - // setTimeout needs to update the polling timeout of the event loop, when - // called under Chromium's event loop the node's event loop won't get a chance - // to update the timeout, so we have to force the node's event loop to - // recalculate the timeout in browser process. - global.setTimeout = wrapWithActivateUvLoop(timers.setTimeout) - global.setInterval = wrapWithActivateUvLoop(timers.setInterval) + global.setTimeout = timers.setTimeout + global.setInterval = timers.setInterval } if (process.platform === 'win32') {