| >> They are nestable
> trycatch is nestable as well. By nestable I mean that you can fork a Zone, configure different values and handlers (for things like intercepting microtasks and timers), and run some code in the forked Zone. All async callbacks spawned from that code will run in the forked Zone. >> intercept microtasks
> Care to elaborate? Dart has an API for scheduling microtasks inside the event loop: scheduleMicrotask(callback). Zones can intercept this call to do things like keep track of the size of the queue and do something when it empties, or manually and synchronously execute the tasks for controlling time in tests. >> wrap closures to be associated with the Zone
> Yup, similar to domains, though I do wonder when this is necessary? It's useful for interacting with external systems and preserving Zone affinity. This is how dart:html ensures that event subscription callbacks are run in the correct Zone, it wraps callbacks (only if necessary - if there's an installed Zone) in the Zone and then hands them to the browser. The wrapper installs the correct Zone before executing the callback. > Long story short, things like keep-alive sockets will retain a domain/context/zone(?) and their handlers will be called with the incorrect context.
>
> Do you fix this in your zone.js implementation? Zone.js is a port of Dart's Zone, so I don't know how faithfully it reproduces it. In Dart, I don't know of any API that doesn't execute callbacks in the correct Zone, except for a bug in dart:js that's being worked on. |