Skip to content

Commit

Permalink
modify SendErr type
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaolong Fu <75103649+191220029@users.noreply.github.com>
  • Loading branch information
191220029 committed Oct 31, 2024
1 parent 6a3f6bd commit 8177b31
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/connection/out_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ impl OutChannels {
/// Perform a blocking send on the outcoming channel from `NodeId`.
pub fn blocking_send_to(&self, id: &NodeId, content: Content) -> Result<(), SendErr> {
match self.get(id) {
Some(channel) => channel.blocking_send(content),
Some(channel) => match channel.blocking_send(content){
Ok(()) => Ok(()),
Err(_) => Err(SendErr::ClosedChannel(content)),
},
None => Err(SendErr::NoSuchChannel),
}
}

/// Perform a asynchronous send on the outcoming channel from `NodeId`.
pub async fn send_to(&self, id: &NodeId, content: Content) -> Result<(), SendErr> {
match self.get(id) {
Some(channel) => channel.send(content).await,
Some(channel) => match channel.send(content).await {
Ok(()) => Ok(()),
Err(_) => Err(SendErr::ClosedChannel(content)),
},
None => Err(SendErr::NoSuchChannel),
}
}
Expand Down Expand Up @@ -91,15 +97,13 @@ impl OutChannel {

/// # Output Channel Error Types
/// - NoSuchChannel: try to get a channel with an invalid `NodeId`.
/// - MpscError: An error related to mpsc channel.
/// - BcstError: An error related to broadcast channel.
/// - ClosedChannel: the channel is closed alredy.
///
/// In cases of getting errs of type `MpscError` and `BcstError`, the sender
/// will find there are no active receivers left, so try to send messages is
/// meaningless for now.
#[derive(Debug)]
pub enum SendErr {
NoSuchChannel,
MpscError(mpsc::error::SendError<Content>),
BcstError(broadcast::error::SendError<Content>),
ClosedChannel(Content),
}

0 comments on commit 8177b31

Please sign in to comment.