Last active
March 25, 2019 10:08
-
-
Save JiaLiPassion/e4daaad3789a8f91fb0f364a75e7a7a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var originalDelegate = window.setTimeout; | |
window.setTimeout = function(callback, delay) { | |
var zone = Zone.current; | |
var task = { | |
zone: zone, | |
type: 'macroTask', | |
source: 'setTimeout', | |
data: { | |
delay: delay | |
}, | |
callback: callback, | |
schedule: () => { | |
task.zone.onScheduleTask(..., zone, task); | |
task.zone.macroTaskCount ++; | |
if (task.zone.macroTaskCount === 1) { | |
task.zone.onHasTask(...,zone, {macroTask: true}); | |
} | |
originalDelegate.call(window, function() { | |
task.zone.onInvokeTask(..., zone, task, this); | |
var result = task.callback.call(this, delay); | |
task.zone.macroTaskCount --; | |
if (task.zone.macroTaskCount === 0) { | |
task.zone.onHasTask(...,zone, {macroTask: false}); | |
} | |
return result; | |
}, task.data.delay); | |
return task; | |
} | |
}; | |
// onSchedule hooks | |
task = task.schedule(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment