Skip to content

Instantly share code, notes, and snippets.

@shkschneider
Last active November 28, 2018 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shkschneider/a9daec72610c966821ed5dd064020edb to your computer and use it in GitHub Desktop.
Save shkschneider/a9daec72610c966821ed5dd064020edb to your computer and use it in GitHub Desktop.
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