is there a good course or tutorial for Coroutines ...
# coroutines
v
is there a good course or tutorial for Coroutines & Flows, I am a bit confused how and when to create which scopes
p
The scope is the same one.
v
Oh no I just meant in general, how and when to create scopes
Like when should I use RunBlocking vs creating a Coroutine Scope, and how do nested scopes relate to one another
p
Are you on Android or other platform? In the case of Android, if you are using the Androidx set of libraries, you get some scopes for granted. Anything that has a lifecycle has a lifecyclescope. In this case Activity, Fragment. ViewModels also have one. You can create one in your Application class. There is also GlobalScope from coroutine lib itself but is not encouraged to use it. Ideally you should create a scope out of a component that has "lifecycle". Then you create the scope when this component is created and cancel the scope when the component is destroyed.
v
Pure JVM, mainly SpringBoot apps
p
I see, I am really not familiar with SpringBoot framework. But in general the "lifecycle" concept applies. I guess you can have a CoroutineScope that has the scope of the SpringApplication. You could also create CoroutineScopes that has the lifecycle of a RequestController. You would get a better answer on the server channel or SpringBoot dedicated channel.
v
I see, will use that as a starting point, really appreciate the insight
đź‘Ť 1
e
I answered a similar question on coroutinescopes on reddit. Check my answer if you’re interested: https://www.reddit.com/r/Kotlin/comments/9x705v/how_to_use_coroutine_scope/e9rg7sh?utm_source=share&utm_medium=web2x
Only change I would make in my original answer is I would use
SupervisorJob()
instead of
Job()
so coroutines launched in the service’s scope can fail independently of one another
v
Thanks Evan, will for sure take a look