-
Notifications
You must be signed in to change notification settings - Fork 39
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
Inline Sender
into Address
#141
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ee46a5e
Move `WaitingSender` to `inbox` module
thomaseizinger 6a41497
Introduce accessor functions for sender and receiver count
thomaseizinger 61c4154
Use `Chan` inside `SendFuture` instead of `Sender`
thomaseizinger 950cbae
Introduce `TxStrong::first`
thomaseizinger 2e9bfb7
Inline `Sender` into `Address`
thomaseizinger e4c440b
Run rustfmt
thomaseizinger d1b30bc
Fix rustdoc
thomaseizinger 91e48f5
Fix debug fmt tests
thomaseizinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,8 @@ use futures_core::FusedFuture; | |
use futures_util::FutureExt; | ||
|
||
use crate::envelope::BroadcastEnvelopeConcrete; | ||
use crate::inbox::tx::TxRefCounter; | ||
use crate::inbox::{SendFuture, SentMessage}; | ||
use crate::{inbox, Error, Handler}; | ||
use crate::inbox::{Chan, SendFuture, SentMessage}; | ||
use crate::{Error, Handler}; | ||
|
||
/// A [`Future`] that represents the state of broadcasting a message to all actors connected to an | ||
/// [`Address`](crate::Address). | ||
|
@@ -23,19 +22,16 @@ use crate::{inbox, Error, Handler}; | |
/// case the mailbox of an actor is bounded, this future yields `Pending` until a slot for this | ||
/// message is available. | ||
#[must_use = "Futures do nothing unless polled"] | ||
pub struct BroadcastFuture<A, M, Rc: TxRefCounter> { | ||
inner: Inner<A, M, Rc>, | ||
pub struct BroadcastFuture<A, M> { | ||
inner: Inner<A, M>, | ||
} | ||
|
||
impl<A, M, Rc> BroadcastFuture<A, M, Rc> | ||
where | ||
Rc: TxRefCounter, | ||
{ | ||
pub(crate) fn new(message: M, sender: inbox::Sender<A, Rc>) -> Self { | ||
impl<A, M> BroadcastFuture<A, M> { | ||
pub(crate) fn new(message: M, chan: Arc<Chan<A>>) -> Self { | ||
Self { | ||
inner: Inner::Initial { | ||
message, | ||
sender, | ||
chan, | ||
priority: None, | ||
}, | ||
} | ||
|
@@ -47,11 +43,13 @@ where | |
pub fn priority(self, priority: u32) -> Self { | ||
match self.inner { | ||
Inner::Initial { | ||
message, sender, .. | ||
message, | ||
chan: sender, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: Remove this extra binding. |
||
.. | ||
} => Self { | ||
inner: Inner::Initial { | ||
message, | ||
sender, | ||
chan: sender, | ||
priority: Some(priority), | ||
}, | ||
}, | ||
|
@@ -60,19 +58,18 @@ where | |
} | ||
} | ||
|
||
enum Inner<A, M, Rc: TxRefCounter> { | ||
enum Inner<A, M> { | ||
Initial { | ||
message: M, | ||
sender: inbox::Sender<A, Rc>, | ||
chan: Arc<Chan<A>>, | ||
priority: Option<u32>, | ||
}, | ||
Sending(SendFuture<A, Rc>), | ||
Sending(SendFuture<A>), | ||
Done, | ||
} | ||
|
||
impl<A, M, Rc> Future for BroadcastFuture<A, M, Rc> | ||
impl<A, M> Future for BroadcastFuture<A, M> | ||
where | ||
Rc: TxRefCounter, | ||
M: Clone + Send + Sync + 'static + Unpin, | ||
A: Handler<M, Return = ()>, | ||
{ | ||
|
@@ -84,13 +81,15 @@ where | |
match mem::replace(&mut this.inner, Inner::Done) { | ||
Inner::Initial { | ||
message, | ||
sender, | ||
chan, | ||
priority, | ||
} => { | ||
let envelope = | ||
BroadcastEnvelopeConcrete::<A, M>::new(message, priority.unwrap_or(0)); | ||
this.inner = | ||
Inner::Sending(sender.send(SentMessage::ToAllActors(Arc::new(envelope)))); | ||
this.inner = Inner::Sending(SendFuture::New { | ||
chan, | ||
msg: SentMessage::ToAllActors(Arc::new(envelope)), | ||
}); | ||
this.poll_unpin(cx) | ||
} | ||
Inner::Sending(mut send_fut) => match send_fut.poll_unpin(cx) { | ||
|
@@ -107,9 +106,8 @@ where | |
} | ||
} | ||
|
||
impl<A, M, Rc> FusedFuture for BroadcastFuture<A, M, Rc> | ||
impl<A, M> FusedFuture for BroadcastFuture<A, M> | ||
where | ||
Rc: TxRefCounter, | ||
Self: Future, | ||
{ | ||
fn is_terminated(&self) -> bool { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just to check, does this properly compare data ptrs and not vtables?
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.
According to the docs, yes: https://doc.rust-lang.org/std/sync/struct.Arc.html#method.ptr_eq
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.
ptr::eq
has this same issue, as far as I know.as_ptr
might explicitly return the data ptr, but it might also return*const dyn _
, which would not be enough to ensure data equality is being tested. See rust-lang/rust#80505 for moreThere 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.
Interesting, I guess this also needs to be changed then.