Thank you <@U0BFDUP0E>, with your extension plus t...
# coroutines
i
Thank you @jw, with your extension plus this one:
Copy code
suspend fun suspendCoroutineWithoutReturn(fn: (Continuation<Unit>) -> Unit) = suspendCoroutine(fn)
I was able to get exactly what i wanted:
Copy code
suspend fun <T : AppCompatActivity> T.awaitRunOnUi(fn: T.() -> Unit) {
    suspendCoroutineWithoutReturn { continuation ->
        runOnUiThread {
            fn()
            continuation.resume()
        }
    }
}
l
@Icaro Temponi Why don't you just use
withContext(Dispatchers.Main) { ... }
?
i
well... I don't know xD, I really should, ty, how could i forget about that
Thank you for pointing that out @louiscad that definitely simplified my code and i even made a function to further reduce it (for espresso):
Copy code
suspend fun <T> onUi(fn: suspend CoroutineScope.() -> T): T =
        withContext(Dispatchers.Main, fn)
l
@Icaro Temponi You can make it inline (with noinline lamba parameter) to avoid overhead
i
oh, i see, i'll do it, thanks again 🙂
Copy code
suspend inline fun <T> onUi(noinline fn: suspend CoroutineScope.() -> T): T =
        withContext(Dispatchers.Main, fn)
Something like this?
l
Yes. You can also rename
fn
to
block
for more consistency regarding kotlinx.coroutines
i
Ok, thanks again 😉