# How to use Channel.isClosedForReceive?

**URL:** <https://discuss.kotlinlang.org/t/how-to-use-channel-isclosedforreceive/6798>\
**Category:** Support\
**Created:** [February 27, 2018, 7:52am UTC](https://discuss.kotlinlang.org/t/how-to-use-channel-isclosedforreceive/6798 "2018-02-27T07:52:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaccozilla](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@jaccozilla](https://discuss.kotlinlang.org/u/jaccozilla)\
**Post date:** [February 27, 2018, 7:52am UTC](https://discuss.kotlinlang.org/t/how-to-use-channel-isclosedforreceive/6798/1 "2018-02-27T07:52:00Z")

</div>

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](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental.channels/-send-channel/close.html), 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](https://stackoverflow.com/questions/48999564/kotlin-wait-for-channel-isclosedforreceive)

---

<div class="post-metadata">

**Author:** ![elizarov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/elizarov/32/2164_2.png) [@elizarov](https://discuss.kotlinlang.org/u/elizarov)\
**Post date:** [February 27, 2018, 3:22pm UTC](https://discuss.kotlinlang.org/t/how-to-use-channel-isclosedforreceive/6798/2 "2018-02-27T15:22:59Z")

</div>

I’ve answered on stack overflow.
