-
-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Feature Description
Change ActorRef and Recipient holding references to other actors in all kameo_actor actors to WeakActorRef and WeakRecipient.
Motivation
All kameo_actor actors, with the exception of Scheduler, use ActorRef and Recipient references to other actors. This makes it a lot harder to implement dynamically created and destroyed actors which want to subscribe to a Broker for example. With PubSub that's probably even not possible, as there's no unsubscribe functionality in that actor (it will keep the subscribed reference until it is destroyed itself).
Example: I'm using Warp to create a websocket server and I have a WebSocketHandler actor, which is spawned by Warp when a new websocket connection is made. That actor lives as long as the client is connected and is destroyed afterwards. I'd like to use PubSub to subscribe WebSocketHandler to some events in the application and it needs to be able to be destroyed together with its subscription.
Alternatives Considered
Switching to WeakActorRef and WeakReference is probably going to break backward compatibility if this is changed in the messages themselves. To keep the backward compatibility the references would need to be downgraded internally in the actors.
Alternatively a second set of messages could be added which would take Weak* references instead of non-weak ones and store and handle weak and non-weak references separately (maybe there are situations where someone would want to have the only reference to their actors stored in these actors).