Skip to content

Commit 10dc097

Browse files
committed
docs: add docs about cancellation safety of Sender
1 parent f3e0ac8 commit 10dc097

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ pub mod channel {
446446

447447
impl<T: RpcMessage> Sender<T> {
448448
/// Send a message and yield until either it is sent or an error occurs.
449+
///
450+
/// ## Cancellation safety
451+
///
452+
/// If the future is dropped before completion, and if this is a remote sender,
453+
/// then the sender will be closed and further sends will return an [`io::Error`]
454+
/// with [`io::ErrorKind::BrokenPipe`]. Therefore, make sure to always poll the
455+
/// future until completion if you want to reuse the sender or any clone afterwards.
449456
pub async fn send(&self, value: T) -> std::result::Result<(), SendError> {
450457
match self {
451458
Sender::Tokio(tx) => {
@@ -469,6 +476,13 @@ pub mod channel {
469476
/// all.
470477
///
471478
/// Returns true if the message was sent.
479+
///
480+
/// ## Cancellation safety
481+
///
482+
/// If the future is dropped before completion, and if this is a remote sender,
483+
/// then the sender will be closed and further sends will return an [`io::Error`]
484+
/// with [`io::ErrorKind::BrokenPipe`]. Therefore, make sure to always poll the
485+
/// future until completion if you want to reuse the sender or any clone afterwards.
472486
pub async fn try_send(&mut self, value: T) -> std::result::Result<bool, SendError> {
473487
match self {
474488
Sender::Tokio(tx) => match tx.try_send(value) {

0 commit comments

Comments
 (0)