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 .
  1. let originalPromiseThen = Promise.prototype.then;
  2. // NOTE: this is simplified as actual API has more arguments.
  3. // Capture the current zone
  4. let capturedZone = Zone.current;
  5. // Return a closure which executes the original closure in zone.
  6. };
  7. // Invoke the original callback in the captured zone.
  8. };
  • 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较多,在此示例中未显式显示。