How to use Channel.isClosedForReceive?

I’m using a Channel to send messages to a processor. I wan’t to close the channel and then return the max message processed. My understanding, based on the doc in Channel.isClosedForReceive, is after calling close() there may be messages in the channel which will be processed before the receivers see the “close token” and stop processing. The same doc makes me think that if I wait for isClosedForReceive == true after calling close() then it is guaranteed no more messages will be received and processed from the Channel.

If the above is true, then what is the best way to wait for isClosedForReceive == true? Ideally I’d like some suspending function, but do not see one. Or maybe there is a pattern I’m not aware of to wait for acondition in a nice, suspending, way.

I’ve also posed this on StackOverflow

I’ve answered on stack overflow.