Are these two code snippets equivalent? ```val job...
# coroutines
v
Are these two code snippets equivalent?
Copy code
val job = SupervisorJob()
val lifecycleScope = CoroutineScope(Dispatchers.Main + job)

lifecycleScope.launch { }
Copy code
val job = SupervisorJob()
val lifecycleScope = CoroutineScope(job)

lifecycleScope.launch(Dispatchers.Main) { }
o
I would say not entirely equivalent -- the two `lifecycleScope`s obviously have different final contexts, but the code in
launch
will be run in the same way, if that was the question
v
ok that was my main question. Why would the context be different? would it need to be
Copy code
lifecycleScope.launch(Dispatchers.Main + job) { }
ie: if I cancel job in the second snippet, it still cancels that
launch
correct?
o
the context is different in that any
launch
(or async, etc.) would use the Main dispatcher by default in the first one, but only the single launch in the second one uses Main by default
👍 3
the job cancellation would still work the same
only the
coroutineContext[CoroutineInterceptor]
would differ -- no other element
1
v
ok perfect! thank you!