Skip to content

Instantly share code, notes, and snippets.

@msgile
Created June 16, 2017 18:25
Show Gist options
  • Save msgile/9d5b30970e2f0b8073d04efed6fb63db to your computer and use it in GitHub Desktop.
Save msgile/9d5b30970e2f0b8073d04efed6fb63db to your computer and use it in GitHub Desktop.
Kotlin example of using coroutines
fun computer(): Int = runBlock {
val partA = async(CommonPool) { computeA() }
val partB = async(CommonPool) { computeB() }
partA.await() + partB.await() //last command emits results
}
val total = computer() // = 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment