Yup. Using another/new CoroutineScope instance is like switching to another/new lifecycle. The calling CoroutineScope’s lifecycle is no longer honored inside the new one.
If you want to switch dispatcher or something, use
withContext(myDispatcher)
or
launch(myDispatcher)
etc.
👍 1
streetsofboston
04/22/2020, 10:15 PM
It has its uses, though, switching between lifecycles by running coroutines on different CoroutineScopes. But you’ll have to be careful 🙂
a
Antanas A.
04/23/2020, 7:58 AM
IMO structured concurrency is very fragile and you need to be very careful not to break it. Without experience is not possible to maintain structured concurrency and you barely can know is it works or not.
E.g.
when you are doing CoroutineScope.launch(context + Job()) structure concurrency is immediately
So actually CoroutineScope.launch(context + Job()) is equals to GlobalScope.launch(context + Job())