Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
in electron, we only patch timers.setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed May 6, 2017
1 parent fe07a8f commit 17bf9b5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import './events';
import './fs';

import {patchTimer} from '../common/timers';
import {findEventTask, patchMacroTask, patchMicroTask} from '../common/utils';
import {findEventTask, isMix, patchMacroTask, patchMicroTask} from '../common/utils';

const set = 'set';
const clear = 'clear';
Expand All @@ -24,8 +24,11 @@ Zone.__load_patch('node_timers', (global: any, Zone: ZoneType, api: _ZonePrivate
try {
const timers = require('timers');
let globalEqualTimersTimeout = global.setTimeout === timers.setTimeout;
if (!globalEqualTimersTimeout) {
// if global.setTimeout not equal timers.setTimeout, check
if (!globalEqualTimersTimeout && !isMix) {
// 1. if isMix, then we are in mix environment such as Electron
// we should only patch timers.setTimeout because global.setTimeout
// have been patched
// 2. if global.setTimeout not equal timers.setTimeout, check
// whether global.setTimeout use timers.setTimeout or not
const originSetTimeout = timers.setTimeout;
timers.setTimeout = function() {
Expand All @@ -43,6 +46,12 @@ Zone.__load_patch('node_timers', (global: any, Zone: ZoneType, api: _ZonePrivate
// timers module not exists, for example, when we using nativescript
// timers is not available
}
if (isMix) {
// if we are in mix environment, such as Electron,
// the global.setTimeout has already been patched,
// so we just patch timers.setTimeout
return;
}
if (!globalUseTimeoutFromTimer) {
// 1. global setTimeout equals timers setTimeout
// 2. or global don't use timers setTimeout(maybe some other library patch setTimeout)
Expand Down

0 comments on commit 17bf9b5

Please sign in to comment.