Hi. We create a Coroutine Scope, and call a functi...
# android
m
Hi. We create a Coroutine Scope, and call a function inside launch. What's the difference between making that function "suspend" and "not suspend(regular)" ?!
l
suspend functions can call CoroutineContext funtions like
delay()
or
withContext()
. you will have access to the scope of the coroutine inside of that suspend function.
a regular function won’t have access to any of the coroutines magic
m
Oh nice. Thanks.
z
Whether a function is suspending or takes a scope also implies something about its behavior by convention. If a function has the suspend modifier, it implies it does some asynchronous work and won't return until that work has finished. If a function is not suspending but takes a scope, it implies that function will launch a new coroutine to start some async work and then return immediately. It's an anti-pattern for a function to both have the suspend modifier and take an explicit scope.