flume icon indicating copy to clipboard operation
flume copied to clipboard

Awaiting disconnection of Receiver or Sender

Open Kijewski opened this issue 3 years ago • 2 comments

I want to do something similar to this:

let msg = select! {
    tx.disconnected() => return Err("disconnected");
    result = read_some_stream() => result?,
};
let msg = process(msg);
if tx.send_async(msg).await.is_err() {
    return Err("disconnected");
}

I.e. I want to asynchronously read from some source, and pass the result to a channel. If the channel gets disconnected in the meantime, I want to know that immediately, not only when I send a message.

Would it be possible to add such a feature? I did try to read the code and to implement it myself, but I failed miserably.

Kijewski avatar Mar 02 '23 15:03 Kijewski

I think implementing a disconnect signal would probably take some time. Is it not feasible to have the thread/task on the other end of the channel to send some sort of shutdown signal?

zesterer avatar Mar 02 '23 15:03 zesterer

Yes, I could use a CancellationToken for example. I thought maybe you would know a simple way to implemented that feature.

I think it such a method would be nice to have in flume itself, but if it does not get added, that would not be too terrible either.

Kijewski avatar Mar 02 '23 16:03 Kijewski