Skip to content

Instantly share code, notes, and snippets.

@JiaLiPassion
Last active March 25, 2019 12:08
Show Gist options
  • Save JiaLiPassion/93cf4e3b186bcfedf8f92165b5aed190 to your computer and use it in GitHub Desktop.
Save JiaLiPassion/93cf4e3b186bcfedf8f92165b5aed190 to your computer and use it in GitHub Desktop.
var zone = Zone.current.fork({
name: 'hook',
onScheduleTask(delegate, current, target, task) {
console.log('schedule ZoneTask', task.type, task.source);
return delegate.scheduleTask(target, task);
},
onInvokeTask(delegate, current, target, task, applyThis, applyArgs) {
console.log('invoke ZoneTask', task.type, task.source);
return delegate.invokeTask(target, task, applyThis, applyArgs);
},
onHasTask(delegate, current, target, hasTaskState) {
console.log('hasTask state: ', hasTaskState);
return delegate.hasTask(target, hasTaskState);
}
});
zone.run(() => {
setTimeout(function() {
console.log('timer callback invoked');
}, 1000);
});
// schedule ZoneTask macroTask setTimeout
// hasTask state {macroTask: true, microTask: false, eventTask: false}
// invoke ZoneTask macroTask setTimeout
// timer callback invoked
// hasTask state {macroTask: false, microTask: false, eventTask: false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment