July 2018
Intermediate to advanced
266 pages
7h 11m
English
There are a few validations that you can perform before trying to send elements through the channel. The most common one is to validate that the channel has not been closed for sending. To do this, you can use isClosedForSend:
val channel = Channel<Int>()channel.isClosedForSend // falsechannel.close()channel.isClosedForSend // true
You can also check whether the channel is out of capacity. When a channel is full, it will suspend the next time you call send, so this property is useful if you would prefer not to suspend your coroutine at the moment:
val channel = Channel<Int>(1)channel.isFull // falsechannel.send(1)channel.isFull // true
Read now
Unlock full access