There seems to be an open question about how to handle passing mutable state 
between actors (or possibly just disallowing it). I have a germ of an idea, and 
I thought I would share in case it triggers a more fully formed idea in someone.

We should have an extremely easy way to wrap a bit of mutable state in a bubble 
of the actor that owns it… or rather, we should be able to effortlessly create 
a proxy to mutable state within an actor (either objects, global properties, or 
closures) for sharing with another actor.  For objects, the proxy would 
basically convert method calls to asynchronous messages. In my mind, the 
wrapper would hold a reference to the actor’s internal queue, and would forward 
the message to the object/closure within that queue, then asynchronously return 
the value (if any) to the calling actor.

Note that this is different than having properties/methods on the actor itself, 
since the wrapper/proxy might not be shared publicly, and it can be passed 
around like an object/closure.  It allows a bunch of patterns that aren’t 
possible otherwise.  For example, I could ask an actor for a callback closure 
to call when something has been completed… and the callback that I receive 
might be unique to me, which allows the actor to field multiple requests 
asynchronously/independently (Instead of having to track state internally, it 
can just use the closure to clean up).

Thoughts?

Thanks,
Jon
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to