Created
December 20, 2018 23:44
-
-
Save twyatt/26ed17fc4b8193154f3608d76ec2c290 to your computer and use it in GitHub Desktop.
Example code for "The Tale of the Misleading Coroutine Stacktrace" article
This file contains 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.* | |
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
fun main(args: Array<String>) = runBlocking<Unit> { | |
val channel = Channel<Int>(CONFLATED) | |
launch { | |
channel.receive() | |
} | |
// Let's emulate another thread launching a Coroutine to shutdown our task. | |
launch { | |
delay(200L) | |
channel.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment