Last active
June 23, 2017 07:01
-
-
Save sys1yagi/7446fd86381a4d0accca19bac627ce47 to your computer and use it in GitHub Desktop.
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
fun <T> async(context: CoroutineContext = CommonPool, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T) | |
= kotlinx.coroutines.experimental.async(context, start, block) | |
fun ui(start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit) | |
= launch(UI, start, block) | |
suspend fun <T, U> parallel(c1: suspend CoroutineScope.() -> T, c2: suspend CoroutineScope.() -> U): Pair<T, U> { | |
val c1Job = async(block = c1) | |
val c2Job = async(block = c2) | |
return Pair(c1Job.await(), c2Job.await()) | |
} | |
suspend fun <T, U, V> parallel(c1: suspend CoroutineScope.() -> T, c2: suspend CoroutineScope.() -> U, c3: suspend CoroutineScope.() -> V): Triple<T, U, V> { | |
val c1Job = async(block = c1) | |
val c2Job = async(block = c2) | |
val c3Job = async(block = c3) | |
return Triple(c1Job.await(), c2Job.await(), c3Job.await()) | |
} |
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
val (user, article) = parallel( | |
{ usersApi.me() }, | |
{ articlesApi.getPublicTimeline() } | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment