You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I might be missing something obvious but I think the conclusion (you can't pass messages through the zone global) is pretty obvious since you can't persist it in any way, even if you set it through an explicit .wrap call by the time someone else gets it it gets changed to their context.
Assume A and B, two players that want to pass a message in JavaScript, the only way they can communicate through zones (Assuming Zone is frozen except for .current which only gets set through wrap/run calls).
If A sets Zone.current through calling wrap/run, that can only affect the call stack inside that Zone.current call. If B ever gets to execute it means that either:
B is running in the global context, in which all zones have been cleared so the call stack has been restored (this can be proven more formally inductively on the number of contexts entered) - Zone.current is the global zone - and A can't communicate anything.
B is running a callback, that callback was wrapped with a Zone.run/wrap (or implicitly):
then it must have been inside one of B's contexts (formal proof - inductively, showing that wrapping preserves the B-ness of the context). This requires some more formality but it should be easy.
Basically, every time A executes or gets to set/unset the zone it also must unset the zone and restore it back - this stems from the definition of the zone spec.
At https://esdiscuss.org/topic/fwd-are-zones-global-state-do-they-provide-a-dangerous-communications-channel we argue that they play together perfectly well. But it is a subtle enough argument that we may have overlooked something. We need to reexamine this argument carefully, possibly formalizing it, so that we can either find a flaw or become confident that it is correct.
The text was updated successfully, but these errors were encountered: