-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat(blocking::mpsc): add Sender::send(_ref)_timeout
methods
#79
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, this looks good to me, except for some minor documentation issues! i'm going to make the suggested changes and then go ahead and merge this.
src/mpsc/errors.rs
Outdated
impl SendTimeoutError { | ||
#[cfg(feature = "std")] | ||
pub(crate) fn with_value<T>(self, value: T) -> SendTimeoutError<T> { | ||
match self { | ||
Self::Timeout(()) => SendTimeoutError::Timeout(value), | ||
Self::Closed(()) => SendTimeoutError::Closed(value), | ||
} | ||
} | ||
} | ||
|
||
impl<T> SendTimeoutError<T> { | ||
/// Returns `true` if this error was returned because the channel is still | ||
/// full after the timeout has elapsed. | ||
pub fn is_timeout(&self) -> bool { | ||
matches!(self, Self::Timeout(_)) | ||
} | ||
|
||
/// Returns `true` if this error was returned because the channel has closed | ||
/// (e.g. the [`Receiver`] end has been dropped). | ||
/// | ||
/// If this returns `true`, no future [`try_send`] or [`send`] operation on | ||
/// this channel will succeed. | ||
/// | ||
/// [`Receiver`]: super::Receiver | ||
/// [`try_send`]: super::Sender::try_send | ||
/// [`send`]: super::Sender::send | ||
/// [`Receiver`]: super::Receiver | ||
pub fn is_closed(&self) -> bool { | ||
matches!(self, Self::Timeout(_)) | ||
} | ||
|
||
/// Unwraps the inner `T` value held by this error. | ||
/// | ||
/// This method allows recovering the original message when sending to a | ||
/// channel has failed. | ||
pub fn into_inner(self) -> T { | ||
match self { | ||
Self::Timeout(val) => val, | ||
Self::Closed(val) => val, | ||
} | ||
} | ||
} | ||
|
||
impl<T> fmt::Debug for SendTimeoutError<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str(match self { | ||
Self::Timeout(_) => "SendTimeoutError::Timeout(..)", | ||
Self::Closed(_) => "SendTimeoutError::Closed(..)", | ||
}) | ||
} | ||
} | ||
|
||
impl<T> fmt::Display for SendTimeoutError<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl SendTimeoutError { | |
#[cfg(feature = "std")] | |
pub(crate) fn with_value<T>(self, value: T) -> SendTimeoutError<T> { | |
match self { | |
Self::Timeout(()) => SendTimeoutError::Timeout(value), | |
Self::Closed(()) => SendTimeoutError::Closed(value), | |
} | |
} | |
} | |
impl<T> SendTimeoutError<T> { | |
/// Returns `true` if this error was returned because the channel is still | |
/// full after the timeout has elapsed. | |
pub fn is_timeout(&self) -> bool { | |
matches!(self, Self::Timeout(_)) | |
} | |
/// Returns `true` if this error was returned because the channel has closed | |
/// (e.g. the [`Receiver`] end has been dropped). | |
/// | |
/// If this returns `true`, no future [`try_send`] or [`send`] operation on | |
/// this channel will succeed. | |
/// | |
/// [`Receiver`]: super::Receiver | |
/// [`try_send`]: super::Sender::try_send | |
/// [`send`]: super::Sender::send | |
/// [`Receiver`]: super::Receiver | |
pub fn is_closed(&self) -> bool { | |
matches!(self, Self::Timeout(_)) | |
} | |
/// Unwraps the inner `T` value held by this error. | |
/// | |
/// This method allows recovering the original message when sending to a | |
/// channel has failed. | |
pub fn into_inner(self) -> T { | |
match self { | |
Self::Timeout(val) => val, | |
Self::Closed(val) => val, | |
} | |
} | |
} | |
impl<T> fmt::Debug for SendTimeoutError<T> { | |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
f.write_str(match self { | |
Self::Timeout(_) => "SendTimeoutError::Timeout(..)", | |
Self::Closed(_) => "SendTimeoutError::Closed(..)", | |
}) | |
} | |
} | |
impl<T> fmt::Display for SendTimeoutError<T> { | |
#[cfg(feature = "std")] | |
impl SendTimeoutError { | |
pub(crate) fn with_value<T>(self, value: T) -> SendTimeoutError<T> { | |
match self { | |
Self::Timeout(()) => SendTimeoutError::Timeout(value), | |
Self::Closed(()) => SendTimeoutError::Closed(value), | |
} | |
} | |
} | |
#[cfg(feature = "std")] | |
impl<T> SendTimeoutError<T> { | |
/// Returns `true` if this error was returned because the channel is still | |
/// full after the timeout has elapsed. | |
pub fn is_timeout(&self) -> bool { | |
matches!(self, Self::Timeout(_)) | |
} | |
/// Returns `true` if this error was returned because the channel has closed | |
/// (e.g. the [`Receiver`] end has been dropped). | |
/// | |
/// If this returns `true`, no future [`try_send`] or [`send`] operation on | |
/// this channel will succeed. | |
/// | |
/// [`Receiver`]: super::Receiver | |
/// [`try_send`]: super::Sender::try_send | |
/// [`send`]: super::Sender::send | |
/// [`Receiver`]: super::Receiver | |
pub fn is_closed(&self) -> bool { | |
matches!(self, Self::Timeout(_)) | |
} | |
/// Unwraps the inner `T` value held by this error. | |
/// | |
/// This method allows recovering the original message when sending to a | |
/// channel has failed. | |
pub fn into_inner(self) -> T { | |
match self { | |
Self::Timeout(val) => val, | |
Self::Closed(val) => val, | |
} | |
} | |
} | |
#[cfg(feature = "std")] | |
impl<T> fmt::Debug for SendTimeoutError<T> { | |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
f.write_str(match self { | |
Self::Timeout(_) => "SendTimeoutError::Timeout(..)", | |
Self::Closed(_) => "SendTimeoutError::Closed(..)", | |
}) | |
} | |
} | |
#[cfg(feature = "std")] | |
impl<T> fmt::Display for SendTimeoutError<T> { |
@utkarshgupta137 whoops, sorry about that! I thought I had set up a workflow that publishes to crates.io on tags, but I must not have done that. |
Follow up to #75.