Skip to content

Instantly share code, notes, and snippets.

@yimajo
Last active July 20, 2018 00:36
Show Gist options
  • Save yimajo/671c6d8df7f987a7f73ab28581702cb3 to your computer and use it in GitHub Desktop.
Save yimajo/671c6d8df7f987a7f73ab28581702cb3 to your computer and use it in GitHub Desktop.
Kotlinでsuspend functionだけでDeferredなメソッドを作らずに2つの処理を同時に動かして待ち合わせる
// Kotlin 1.2.51
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.runBlocking
fun main(args: Array<String>) {
runBlocking {
var jobA = async { job() }
var jobB = async { job() }
println(jobA.await() * jobB.await())
println("World")
}
println("Hello")
}
suspend fun job(): Int {
// 非同期処理があるということにしよう。非同期処理した体で適当に10の値を返すよ
return 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment