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
let stream_results = create_stream();
let (tx, mut rx) = futures_channel::mpsc::channel::<u64>(100);
thread::spawn(move || {
let mut f = open("file");
rx.for_each(|data| f.write(data)).wait().unwrap();
f.write("success").unwrap();
});
if let Err((_, e)) = tx.send_all(stream_results).wait() {
println!("send fail: {:?}", e);
}
If stream_results returns error, tx will get dropped silently. In that case, rx will be resolved successfully and success will be written, which is not expected as not all stream results are flush successfully.
This case can be solved by change the channel type u64 to Option<u64>, and use an explicit None to indicate tx is closed. But isn't it more clear to let rx return error when tx is dropped before closing?
The text was updated successfully, but these errors were encountered:
Consider following case:
If
stream_results
returns error,tx
will get dropped silently. In that case,rx
will be resolved successfully andsuccess
will be written, which is not expected as not all stream results are flush successfully.This case can be solved by change the channel type
u64
toOption<u64>
, and use an explicitNone
to indicatetx
is closed. But isn't it more clear to let rx return error when tx is dropped before closing?The text was updated successfully, but these errors were encountered: