Skip to content
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

add Receiver::obtain_sender() and Sender::obtain_receiver() methods #762

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions kernel/async_channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,20 @@ impl <T: Send> Sender<T> {
pub fn is_disconnected(&self) -> bool {
self.channel.is_disconnected()
}


/// Returns a receiver of the given channel
pub fn receiver(&self) -> Receiver<T> {
Receiver {
channel: self.channel.clone(),
}
}
}

//if self.channel.sender_count.fetch_add(1, Ordering::SeqCst) == 0 {
// self.channel.channel_status.store(ChannelStatus::Connected);
//}
//Sender { channel: self.channel.clone() }


/// The receiver side of a channel.
pub struct Receiver<T: Send> {
channel: Arc<Channel<T>>,
Expand Down Expand Up @@ -485,17 +491,16 @@ impl <T: Send> Receiver<T> {
pub fn is_disconnected(&self) -> bool {
self.channel.is_disconnected()
}


/// Returns a sender of the given channel
pub fn sender(&self) -> Sender<T> {
Sender {
channel: self.channel.clone(),
}
}
}


/// When the only remaining `Receiver` is dropped, we mark the channel as disconnected
/// and notify all of the `Senders`
/// Drop implementation marks the channel state and notifies the `Sender`
impl<T: Send> Drop for Receiver<T> {
fn drop(&mut self) {
// trace!("Dropping a receiver");
Expand All @@ -506,8 +511,7 @@ impl<T: Send> Drop for Receiver<T> {
}
}

/// When the only remaining `Sender` is dropped, we mark the channel as disconnected
/// and notify all of the `Receivers`
/// Drop implementation marks the channel state and notifies the `Receiver`
impl<T: Send> Drop for Sender<T> {
fn drop(&mut self) {
// trace!("Dropping a sender");
Expand Down