Skip to content

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

Open
@BusyJay

Description

@BusyJay

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-channelArea: futures::channel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions