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
streetsofboston
03/02/2020, 4:10 PM
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
Luis Munoz
03/02/2020, 5:09 PM
@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
streetsofboston
03/02/2020, 5:11 PM
That depends on how you scope your CoroutineScope extension functions….