Skip to content
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

channel: should stream receives error when the other part of pair sink is not closed properly? #931

Open
BusyJay opened this issue Apr 2, 2018 · 0 comments
Labels
A-channel Area: futures::channel

Comments

@BusyJay
Copy link
Contributor

BusyJay commented Apr 2, 2018

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?

@taiki-e taiki-e added the A-channel Area: futures::channel label Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-channel Area: futures::channel
Projects
None yet
Development

No branches or pull requests

2 participants