-
-
Notifications
You must be signed in to change notification settings - Fork 83
[FEATURE] - Use WeakActorRef and WeakRecipient in kameo_actors #268
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Feature Description
Change
ActorRefandRecipientholding references to other actors in allkameo_actoractors toWeakActorRefandWeakRecipient.Motivation
All
kameo_actoractors, with the exception ofScheduler, useActorRefandRecipientreferences to other actors. This makes it a lot harder to implement dynamically created and destroyed actors which want to subscribe to aBrokerfor example. WithPubSubthat'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
WebSocketHandleractor, 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 subscribeWebSocketHandlerto some events in the application and it needs to be able to be destroyed together with its subscription.Alternatives Considered
Switching to
WeakActorRefandWeakReferenceis 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).