I am uncertain when to use suspend fun verses Coro...
# coroutines
l
I am uncertain when to use suspend fun verses CoroutineScope extension function, is there a documentation that says why to prefer one over the other?
s
Use
suspend fun
when the return (value) of the function takes a while. The function suspends for a while and after a while it returns (a value). And you can call
suspend fun
only from a Coroutine or other suspend funs. Use a CoroutineScope extension function to kick off something asynchronously and the function should return immediately (the CoroutineScope extension function should never suspend)
l
@streetsofboston doesn't it feel messy having extension functions on coroutines because you don't have good modularity. In every coroutine now I have access to a list of functions that are not related in anyway to where the code is
s
That depends on how you scope your CoroutineScope extension functions….
✔️ 2