-
Notifications
You must be signed in to change notification settings - Fork 472
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
Add disconnected flavor which immediately fails #1047
base: master
Are you sure you want to change the base?
Conversation
@@ -274,6 +274,13 @@ pub fn never<T>() -> Receiver<T> { | |||
} | |||
} | |||
|
|||
/// Creates a receiver that is disconnected always. |
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.
I'm happy to expand this doccomment with an example, which will be based on the one in the pr description with polishes, once it's confirmed that this pr has some hope to be merged.
} | ||
|
||
impl<T> Channel<T> { | ||
/// Creates a channel that always delivers messages. |
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.
oops forgot to update..
Thanks for the PR. I guess this could be replaced by never + disconnect once the API for explicit disconnection is exposed? |
hey, really thanks for replying! yeah, assuming the disconnected never is implemented in a hard-coded way without any state much like the never itself for maximum optimization opportunity by rustc. note that the tick approach in the pr description or just |
i think disconnected dummy sender might also be useful. ref: #750 how about this api? |
Yet another small niceties, i'd like to add to
crossbeam_channel
.This doesn't look meaningful by itself at first glance. However, this is useful for conditionally inserting an artificial select arm at predetermined priority in the
select_biased!()
#1040, combined withnever()
like this:Note that using
tick()
like below introduces needless calls toInstant::now()
(which is a vdso basically) per select invocation on top of the needless stack memory consumption. (On the other hand, the zst &const
-code-heavydisconnected()
will be optimized out to great degree after the macro expansion)..:Also, unrolling the select is possible, but creates code duplication. Lastly, checking
is_local_task_available
afterselect_biased!()
alone would introduce a priority inversion.Thus, i think there's no acceptable alternative solution currently.