I want to make sure that I am getting the conventi...
# coroutines
m
I want to make sure that I am getting the conventions right. There are two types of functions that will not block the invoker thread: A - when it doesn't block because it suspends (
suspend fun
) B - when it doesn't block because it will delegate the operation to a different thread (`Deferred<T>`/`Job`) The convention, from what I have gathered from presentations+docs would be: - Prefer
A
and name the method as you would normally, but of course make it a suspendable function.
suspend fun doSomethingNetworkRelated()
- If you have to use
B
(e.g because the platform/code you use doesn't support non-blocking IO), name your function so that the invoker knows that they should `await()`/`join()` to guarantee that the computation ends before they continue. For example
asyncFetchProfile
or
fetchProfileAsync
. Makes sense?
👍 2