Zone 传播 - 异步操作补丁
优质
小牛编辑
133浏览
2023-12-01
- Zones 的猴子补丁方法只修补一次。
- 进入/离开 zone 只需更改Zone.current的值。(不需要进一步的猴子补丁)
- Zone.prototype.wrap method provides convenience for wrapping callbacks. (The wrapped callback is executed through Zone.prototype.runGuarded())
- Zone.prototype.runGuarded() is just like Zone.prototype.run(), but with extra try-catch block for handling exceptions .
let originalPromiseThen = Promise.prototype.then;
// NOTE: this is simplified as actual API has more arguments.
// Capture the current zone
let capturedZone = Zone.current;
// Return a closure which executes the original closure in zone.
};
// Invoke the original callback in the captured zone.
};
- Promises handle their own exceptions and so they can’t use Zone.prototype.wrap(). (We could have separate API, but Promise is the exception to the rule, and so I did not feel justified creating its own API.)
- Promise API较多,在此示例中未显式显示。