And there are some workers that take the lines and … well, work on them. Then they POST them in a HTTP request to an elasticsearch instance. They’re started before the reader takes over the main thread, of course.

Also started before them is another thread, which the focus of this question. It deals with printing progress statistics at intervals, using a collection of AtomicUsize in a struct and shared via lazy_static.

The question is about how to know when this thread should terminate. The others just use the blocking iterator until it’s None. This one is currently checking whether the channel is_empty(). However, this is not strictly correct. In this case it’s very unlikely, but there is a small chance that the input reader stalled on io (it’s reading a pipe from another process) and the workers drained the channel without actually finishing. This isn’t just about stats; I’ve omitted some detail about joining the threads at the end, which basically waits for the stats thread as the overall termination condition for the program.

I need the stats thread to observe the channel state, but not interfere with the contents. It can’t try reading from the channel because it might end up consuming data. It can’t take a copy of the sender instead of the receiver, because that will prevent the sender getting dropped. There’s no is_disconnected() method, and no other way I can see to check this by implied side-effects. A bigger bounded size is probably a sufficient workaround in this case, but this is Rust and I want to be correct

I can also think of some other, separate signalling channels between the threads. Maybe the simplest is to add another field/flag to the stats struct. I’m sure that would work, but it really feels like this is something the channel should be able to tell me directly. Have I missed something? Is this a missing feature?