You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
Wouldn't it be better if the whole async for loop expression evaluated to a possible Err<Stream::Error> if an error occured and Ok(()) otherwise? That way you can do some custom error handling.
Example 1:
let stream = get_stream();let result = #[async]for message in stream {println!("{}", message);};ifletErr(err) = result {println!("An error occured!");}
Example 2:
let stream = get_stream();#[async]for message in stream {println!("{}", message);}.unwrap_or_else(|err| {println!("An error occured!");});
To get the current behavior you just put ? after the loop body:
#[async]for message in stream {
…
}?;
The text was updated successfully, but these errors were encountered:
Yeah this is something I'm not entirely sure how to handle. The ability though for a for loop to have a value isn't something I'd though of before, so may have something promising!
You can do this right now by wrapping the loop in a catch block since #[async] for uses ? on the result of Stream::poll().
let stream = get_stream();let result = do catch{#[async] for message in stream {
println!("{}", message);}Ok(())};ifletErr(err) = result {println!("An error occured!");}
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Wouldn't it be better if the whole async for loop expression evaluated to a possible
Err<Stream::Error>
if an error occured andOk(())
otherwise? That way you can do some custom error handling.Example 1:
Example 2:
To get the current behavior you just put
?
after the loop body:The text was updated successfully, but these errors were encountered: