diff options
Diffstat (limited to 'tokio/src/sync/mpsc/error.rs')
-rw-r--r-- | tokio/src/sync/mpsc/error.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/tokio/src/sync/mpsc/error.rs b/tokio/src/sync/mpsc/error.rs index 802bc488..99193563 100644 --- a/tokio/src/sync/mpsc/error.rs +++ b/tokio/src/sync/mpsc/error.rs @@ -96,7 +96,7 @@ impl Error for TryRecvError {} // ===== ClosedError ===== -/// Erorr returned by [`Sender::poll_ready`](super::Sender::poll_ready)]. +/// Error returned by [`Sender::poll_ready`](super::Sender::poll_ready)]. #[derive(Debug)] pub struct ClosedError(()); @@ -113,3 +113,34 @@ impl fmt::Display for ClosedError { } impl Error for ClosedError {} + +cfg_time! { + // ===== SendTimeoutError ===== + + #[derive(Debug)] + /// Error returned by [`Sender::send_timeout`](super::Sender::send_timeout)]. + pub enum SendTimeoutError<T> { + /// The data could not be sent on the channel because the channel is + /// full, and the timeout to send has elapsed. + Timeout(T), + + /// The receive half of the channel was explicitly closed or has been + /// dropped. + Closed(T), + } + + impl<T: fmt::Debug> Error for SendTimeoutError<T> {} + + impl<T> fmt::Display for SendTimeoutError<T> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + fmt, + "{}", + match self { + SendTimeoutError::Timeout(..) => "timed out waiting on send operation", + SendTimeoutError::Closed(..) => "channel closed", + } + ) + } + } +} |