How can one share a resource, such as a connection, among multiple actors?
I understand the situation if I have a connection pool - then I can make an actor that can pass connections to other actors.
But what if the resource only allows one connection in total, but multiple actors need to access it? This seems to violate the paradigm of “no shared mutable state”. But what if I need it?
I have been considering
- putting the connection into an Akka Extensions, so that multiple actors have access to it
- passing the connection to an actor at creation time
Let’s say for this discussion that the connection object is thread-safe (extra points for a solution that works on non-threadsafe connections)