Last active
November 28, 2018 10:33
-
-
Save shkschneider/a9daec72610c966821ed5dd064020edb 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
object Coroutines { | |
fun io(work: suspend (() -> Unit)): Job = | |
CoroutineScope(Dispatchers.IO).launch { | |
work() | |
} | |
fun <T: Any> ioThenMain(work: suspend (() -> T?), callback: ((T?) -> Unit)): Job = | |
CoroutineScope(Dispatchers.Main).launch { | |
val data = CoroutineScope(Dispatchers.IO).async rt@ { | |
return@rt work() | |
}.await() | |
callback(data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment