https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

Tianyu Zhu

10/06/2023, 8:06 PM
What should I use instead of
GlobalScope
in Kotlin/JS? I can't seem to find any other `CoroutineScope`s to use...
c

Casey Brooks

10/06/2023, 8:09 PM
GlobalScope is discouraged, because it’s better to create your own scope whose lifecycle you control. For example,
MainScope()
or
CoroutineScope(Dispatchers.Default + SupervisorJob())
t

Tianyu Zhu

10/06/2023, 8:13 PM
Is that because if I write
GlobalScope.launch { ... }
the resulting job won't get canceled? Is that because...
GlobalScope
never canceled?
k

kevin.cianfarini

10/06/2023, 8:44 PM
Similar to
async
but returns a promise which can be awaited in js
c

CLOVIS

10/08/2023, 9:28 AM
Is that because...
GlobalScope
never canceled?
Yes
thank you color 1