Skip to content

Instantly share code, notes, and snippets.

@twyatt
Created December 20, 2018 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twyatt/26ed17fc4b8193154f3608d76ec2c290 to your computer and use it in GitHub Desktop.
Save twyatt/26ed17fc4b8193154f3608d76ec2c290 to your computer and use it in GitHub Desktop.
Example code for "The Tale of the Misleading Coroutine Stacktrace" article
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