xactor icon indicating copy to clipboard operation
xactor copied to clipboard

Customizable actor message queue

Open ejmount opened this issue 2 years ago • 0 comments

While using xactor to build an IRC server, I realized that I wanted a different implementation for actors' message queues, so that they would respond to backpressure from other parts of my system. I thought others might have the same problem and appreciate a solution, so I have designed my change to be general and allow the implementor to pick their own type as needed.

This PR replaces the hardcoded Sender and Receiver types the Actor uses to queue messages with a set of associated types that allow for any queue implementation that implements the appropriate traits. However, that queue uses the internal ActorEvent type, and I did not want to expose that unnecessarily. To work around this, I use GATs, so this is only available on Nightly for now. If it is acceptable for ActorEvent to be exposed publicly, even completely opaquely, this would be doable on stable.

I have tried to maintain backwards compatibility by feature-gating and providing defaults so that existing uses will continue exactly working as before even with the feature switched on. The only change I'm aware of that is not gated and immediately backwards compatible is that I had to explicitly constrain the generic parameter for Context, Addr and the like to be an Actor, but I couldn't see how it would be possible to use anything else as that parameter, so I don't think there's any possible breakage.

Let me know any feedback you have or changes you'd like made.

ejmount avatar Sep 08 '21 23:09 ejmount