feat(blocking::mpsc): add Sender::send(_ref)_timeout methods#79
Merged
hawkw merged 5 commits intohawkw:mainfrom Apr 28, 2023
Merged
feat(blocking::mpsc): add Sender::send(_ref)_timeout methods#79hawkw merged 5 commits intohawkw:mainfrom
Sender::send(_ref)_timeout methods#79hawkw merged 5 commits intohawkw:mainfrom
Conversation
hawkw
approved these changes
Apr 28, 2023
Owner
hawkw
left a comment
There was a problem hiding this comment.
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.
hawkw
reviewed
Apr 28, 2023
Comment on lines
113
to
165
| 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> { |
Owner
There was a problem hiding this comment.
Suggested change
| 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> { |
hawkw
reviewed
Apr 28, 2023
hawkw
reviewed
Apr 28, 2023
Contributor
Author
Owner
|
@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. |
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #75.