Skip to content

Commit

Permalink
修改方法名
Browse files Browse the repository at this point in the history
  • Loading branch information
puy committed Apr 18, 2019
1 parent 118492e commit be862cc
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ internal class CoroutineLifecycleListener(private val deferred: Deferred<*>) : L
}
}

fun <T> LifecycleOwner.io(loader: suspend () -> T): Deferred<T> {
fun <T> LifecycleOwner.loadAsync(loader: suspend () -> T): Deferred<T> {
val deferred = GlobalScope.async(Dispatchers.IO, start = CoroutineStart.LAZY) {
loader()
}
lifecycle.addObserver(CoroutineLifecycleListener(deferred))
return deferred
}

infix fun <T> Deferred<T>.main(block: suspend (T) -> Unit): Job {
infix fun <T> Deferred<T>.ui(block: suspend (T) -> Unit): Job {
return GlobalScope.launch(Dispatchers.Main) {
try {
block(this@main.await())
block(this@ui.await())
} catch (e: Exception) {
loge(e) { "Exception in then()!" }
loge(e) { "Exception in ui()!" }
throw e
}
}
Expand Down

0 comments on commit be862cc

Please sign in to comment.