-
Notifications
You must be signed in to change notification settings - Fork 20
ACP: Implement Future
for Option<F>
#197
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
Comments
cc @rust-lang/wg-async who might have opinions |
|
@taiki-e a benefit
|
I did not mean "we shouldn't implement |
Understood, thanks for elaborating. I agree that behavior questions should be resolved before committing to an implementation. Here are my opinions:
|
Another design question for this feature is "should I think the answer should be "no" since iterating over |
Future
for Option<F>
Future
for Option<F>
cc/ @rust-lang/wg-async |
@oli-obk pointed out to me that similar functionality in an let x = try { Some(f?.await) }; Despite this, I think this feature is worth pursuing due to enabling:
|
The problem let x = f.map(async |f| f.await); This limitation does not just apply to //! recommended `Option::map` usage patterns with this API
// sync rust
let x = t.map(|t| f(t));
// async rust
let x = t.await.map(|t| f(t)); This works okay as long as the function |
I was going to bring up this morning the same thing! 😄 @thomcc pointed out to me that the I bet that But I agree that it doesn't solve the situation with other |
We discussed this at some length today in the WG-async call. We came to the consensus that: WG-async does not want this impl to exist and recommends this ACP be closed. Overall, we felt this was a poor workaround for an async In the sense that the impl proposed here would "reach through" the outer type into the future within, some of us thought this was analogous to the We discussed alternate semantics, such as having Work on async closures is proceeding at the moment, and we view that as the main path forward here. |
I have a feeling that returning let conn_primary: Option<TcpStream> = ... // enabled based on config
let conn_secondary: Option<TcpStream> = ... // enabled based on config
loop {
select! {
msg_primary = conn_primary.recv() => {...},
msg_secondary = conn_secondary.recv() => {...},
}
} Returning As a consequence, having |
This feature completed an FCP to close in rust-lang/rust#109691. Thanks anyway for the proposal! And for the insightful comments both in favor and against, and the async WG's considerate review. |
Proposal
Problem statement
When working with an
Option<F: Future>
in anasync
context, one may want to defer the handling ofNone
. This is currently cumbersome/verbose to do.Motivation, use-cases
It is not possible to shorten this to
let x = f.map(|f| f.await)
because theasync
context is not available in a closure.Solution sketches
This is implemented in rust-lang/rust#109691.
Links and related work
Prior art:
OptionFuture
impl Future for Either<L: Future, R: Future>
The text was updated successfully, but these errors were encountered: