Should supervisorScope be inside launch or outside...
# coroutines
j
Should supervisorScope be inside launch or outside launch or doesn't it matter?
Copy code
supervisorScope {
   launch(Dispatchers.Default) {
      supervisorScope {
j
What are you trying to achieve exactly? If
launch
is supposed to be launched in a supervisor scope to avoid cancelling its sibling coroutines when it fails, then it should be inside the
supervisorScope
lambda.
j
Each launch is triggered when a connection happens, so any exception being thrown inside one of these launches should not cancel the other launches being triggered by other connections. Running launch inside supervisorScope sounds like the correct way, but the mental model I have of supervisorScope makes me think it'll work inside launch too.
j
The scope's purpose is to control a set of coroutines. So all the launches that you want to "group" together should be launched in the same supervisor scope, otherwise there is no real point.
👍 1
🙏 1