tonarino / actor

A minimalist actor framework aiming for high performance and simplicity.
MIT License
40 stars 6 forks source link

Context: change myself field from Addr<A> to Recipient<M> #54

Closed strohel closed 3 years ago

strohel commented 3 years ago

This makes whole Context parametrised by M (message), rather than A: Actor. As a result, Context is more flexible to pass on, which facilitates creation of Actor wrappers.

This changes the signature of the Actor trait methods, which breaks the API, though required edits should be mostly mechanical. The field myself was arguably used most for sending messages to oneself, which already went through a Deref to Recipient.

One piece of functionality was lost on Context: the Addr::recipient() method which can produce a "converting" recipient. recipient() can be moved from Addr to Recipient to preserve it. Do you think it is needed?

strohel commented 3 years ago

Note that this is no longer technically a prerequisite of #53 as it no longer depends on wrapping actors. But wrapping actors in general could be still useful, and so could be this PR. Downside is the scale of edits that downstreams would need to make to accommodate this.

There may also be alternative technical approaches. Ability to create Context<BarActor> from &mut Context<FooActor> (perhaps when FooActor::Message implements Into/From<BarActor::Message>) would be one such option. But that approach also looks like requiring a change to the API (and the internals). And message_rx: Receiver<A::Message>, which is currently transitive member of Context<A>, may prevent us from providing such a wrapper. The same message_rx is being removed from Context by this PR.

strohel commented 3 years ago

I've rebased this on master and added an actor wrapping example. We've got quite o lot of examples now, but I'll move delay_actor out soon. I'll merge this tomorrow unless something pops up.