Created
April 15, 2021 08:11
-
-
Save twyatt/ebfa8172bf2a5c37a479864f66834db5 to your computer and use it in GitHub Desktop.
Exceptions thrown when sending to closed/cancelled Channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.coroutineScope | |
suspend fun main() = coroutineScope<Unit> { | |
val receive = Channel<Int>() | |
receive.cancel() // ReceiveChannel | |
// java.util.concurrent.CancellationException: RendezvousChannel was cancelled | |
runCatching { receive.send(1) }.onFailure { println(it) } | |
val send = Channel<Int>() | |
send.close() // SendChannel | |
// kotlinx.coroutines.channels.ClosedSendChannelException: Channel was closed | |
runCatching { send.send(2) }.onFailure { println(it) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment