Skip to content

Instantly share code, notes, and snippets.

@JiaLiPassion
Last active March 25, 2019 10:08
Show Gist options
  • Save JiaLiPassion/e4daaad3789a8f91fb0f364a75e7a7a5 to your computer and use it in GitHub Desktop.
Save JiaLiPassion/e4daaad3789a8f91fb0f364a75e7a7a5 to your computer and use it in GitHub Desktop.
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