Channels and error handling patterns?

Suppose thread/task f does some work, puts values V1, V2, V3, ..., V10 on a channel.

Thread/task g then takes items off the channel and starts processing them.
V1 good
V2 good
V3 good
V4 error!!!

What are the standard patterns for handling these situations? Does g try to notify f (which is now busy with producing V11) ?

The standard Result<T, E> is nice because it forces us to decide how to handle the error. Are there patterns here when dealing with channels ?

The easiest way is to simply drop the receiver, which will cause f to get an error when it tries to send V11. Some channels also have ways to immediately detect the closure so it can abort during the creation of V11 instead of once it completes (e.g. you can use tokio::sync::mpsc::Sender::closed in a select! to cancel V11).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.