Last active
July 20, 2018 00:36
-
-
Save yimajo/671c6d8df7f987a7f73ab28581702cb3 to your computer and use it in GitHub Desktop.
Kotlinでsuspend functionだけでDeferredなメソッドを作らずに2つの処理を同時に動かして待ち合わせる
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
// 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