-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support creating differently-typed recipients in Addr::recipient() #38
Conversation
e4dc775
to
d4acd2e
Compare
d4acd2e
to
1418240
Compare
I've force-pushed v2 of the change. Thanks to @skywhale's clever question, I was able make the change smaller and simpler by not messing up with I've also removed the temporary commit (so that send_if_not_full() is kept for now), and polished the commit adding This should make this PR merge-ready (I suggest not squashing commits during merge). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me! Nice type magic :).
As @bschwind said, the only compromise of this approach vs. impl Handler<MessageType>
is that we can't have different channels per message type to have different priorities per type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great :)
Type inference is pretty powerful.
I.e before this change, Input, Damper actors assumed they are fed into Mixer, but Delay assumed it is fed into something that expects naked `Chunk`. This made no sense, and made actors dependent on how they are wired in the system, which is an antipattern. This is an artificial change that demonstrates problems outlined in #11 (comment)
Thanks to the previous commit, this is now possible to do this _without touching the actors themselves._ Artificial change for demonstration purposes. This brings no change functionality-wise.
...within bounds that that M: Into<N> for Recipient<M> for Actor<Message = N>. Fixes #11 (in its narrow sense) without creating multiple channels per actor and without boxing the messages transferred. Has been made possible by removal of the ability to retrieve back the failed-to-send message in one of the earlier commits. The whole trick is to box crossbeam `Sender<M>` into `Arc<dyn SenderTrait<M>>` in `Receiver`, and implementing `SenderTrait<M>` for crossbeam `Sender` and for boxed version of itself (!), second time with ability to convert `M`. All generic parameters in the echo example have disappeared without losing any flexibility, yay! Speaking strict semver, this is an API-breaking change, but e.g. the media_pipeline compiles and works unchanged. v2: make the change smaller and simpler by not messing up with `GenericReceiver`. Enables nicer API and keeping `SenderTrait` private, at the small expense of one extra boxing when creating `Addr`, and one extra pointer indirection when calling send() family of functions. All that thanks to @skywhale's clever question.
f9644e1
to
c17a353
Compare
Right, this does not resolve #22 along the way. My reasoning was, thinking about the future state with priorities implemented: API-wise, do we want to bind the priority to the message type, or shall we let the sender decide, i.e. bind the priority to the message instance? The sender-decided priority is functionally a superset of message-based priority. That alone doesn't make it a better choice, but I haven't found strong reasons to make the API more opinionated either (thoughts welcome). I've basically pushed that decision to the point when #22 is implemented, though this currently leans on the sender-decided priority side (that was simply a smaller change). I think that #22 shall be relatively straightforward to implement if we start with a small fixed set of priorities ( Now, does this make sense to somebody who's not me? :) |
...within bounds that M: Into for Recipient for Actor<Message = N>.
Fixes #11 (in its narrow sense) without creating multiple channels per actor
and without boxing the messages transferred.
Has been made possible by removal of the ability to retrieve back the
failed-to-send message in one of the earlier commits.
The whole trick is to box crossbeam
Sender<M>
intoArc<dyn SenderTrait<M>>
in
Receiver
, and implementingSenderTrait<M>
for crossbeamSender
and forboxed version of itself (!), second time with ability to convert
M
.All generic parameters in the echo example have disappeared without losing any
flexibility, yay!
Speaking strict semver, this is an API-breaking change, but e.g. the
media_pipeline compiles and works unchanged.
v2: make the change smaller and simpler by not messing up with
GenericReceiver
. Enables nicer API and keepingSenderTrait
private, at thesmall expense of one extra boxing when creating
Addr
, and one extra pointerindirection when calling send() family of functions.
All that thanks to @skywhale's clever question.
I suggest reviewing by commits and not squashing during merge, the main one if the last one.