Skip to content

Commit 4e5fc0b

Browse files
191220029genedna
authored andcommitted
modify SendErr type
Signed-off-by: Xiaolong Fu <[email protected]>
1 parent 48dc8ec commit 4e5fc0b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/connection/out_channel.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ impl OutChannels {
1616
/// Perform a blocking send on the outcoming channel from `NodeId`.
1717
pub fn blocking_send_to(&self, id: &NodeId, content: Content) -> Result<(), SendErr> {
1818
match self.get(id) {
19-
Some(channel) => channel.blocking_send(content),
19+
Some(channel) => match channel.blocking_send(content){
20+
Ok(()) => Ok(()),
21+
Err(_) => Err(SendErr::ClosedChannel(content)),
22+
},
2023
None => Err(SendErr::NoSuchChannel),
2124
}
2225
}
2326

2427
/// Perform a asynchronous send on the outcoming channel from `NodeId`.
2528
pub async fn send_to(&self, id: &NodeId, content: Content) -> Result<(), SendErr> {
2629
match self.get(id) {
27-
Some(channel) => channel.send(content).await,
30+
Some(channel) => match channel.send(content).await {
31+
Ok(()) => Ok(()),
32+
Err(_) => Err(SendErr::ClosedChannel(content)),
33+
},
2834
None => Err(SendErr::NoSuchChannel),
2935
}
3036
}
@@ -91,15 +97,13 @@ impl OutChannel {
9197

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

0 commit comments

Comments
 (0)