Open
Description
Consider following case:
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?