|
1 | | -import * as timers from 'timers' |
2 | 1 | import * as util from 'util' |
3 | 2 |
|
4 | 3 | import { electronBindingSetup } from '@electron/internal/common/electron-binding-setup' |
5 | 4 |
|
| 5 | +const timers = require('timers') |
| 6 | + |
6 | 7 | process.electronBinding = electronBindingSetup(process._linkedBinding, process.type) |
7 | 8 |
|
8 | 9 | type AnyFn = (...args: any[]) => any |
@@ -38,16 +39,20 @@ function wrap <T extends AnyFn> (func: T, wrapper: (fn: AnyFn) => T) { |
38 | 39 |
|
39 | 40 | process.nextTick = wrapWithActivateUvLoop(process.nextTick) |
40 | 41 |
|
41 | | -global.setImmediate = wrapWithActivateUvLoop(timers.setImmediate) |
| 42 | +global.setImmediate = timers.setImmediate = wrapWithActivateUvLoop(timers.setImmediate) |
42 | 43 | global.clearImmediate = timers.clearImmediate |
43 | 44 |
|
| 45 | +// setTimeout needs to update the polling timeout of the event loop, when |
| 46 | +// called under Chromium's event loop the node's event loop won't get a chance |
| 47 | +// to update the timeout, so we have to force the node's event loop to |
| 48 | +// recalculate the timeout in browser process. |
| 49 | +timers.setTimeout = wrapWithActivateUvLoop(timers.setTimeout) |
| 50 | +timers.setInterval = wrapWithActivateUvLoop(timers.setInterval) |
| 51 | + |
| 52 | +// Only override the global setTimeout/setInterval impls in the browser process |
44 | 53 | if (process.type === 'browser') { |
45 | | - // setTimeout needs to update the polling timeout of the event loop, when |
46 | | - // called under Chromium's event loop the node's event loop won't get a chance |
47 | | - // to update the timeout, so we have to force the node's event loop to |
48 | | - // recalculate the timeout in browser process. |
49 | | - global.setTimeout = wrapWithActivateUvLoop(timers.setTimeout) |
50 | | - global.setInterval = wrapWithActivateUvLoop(timers.setInterval) |
| 54 | + global.setTimeout = timers.setTimeout |
| 55 | + global.setInterval = timers.setInterval |
51 | 56 | } |
52 | 57 |
|
53 | 58 | if (process.platform === 'win32') { |
|
0 commit comments