Is `scope.launch(<http://Dispatchers.IO|Dispatcher...
# coroutines
r
Is
scope.launch(<http://Dispatchers.IO|Dispatchers.IO> + SupervisorJob()) { ... }
a good shorthand for when I want to fire & forget?
e
if you're sure that's what you want to do, I'd explicitly write out
GlobalScope
to make it obvious the job isn't scoped (that's effectively
GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) { ... }
)
y
I think you might want to pass the parent job to
SupervisorJob
so that the supervisor and all its children is cancelled when the parent is cancelled. The way to do that is like:
scope.coroutineContext[Job]
e
in that case you might as well use
supervisorScope {
z
If you intentionally want to break structured concurrency, all you need is an orphan job. Choice of supervisor or not, and dispatcher, don’t have anything to do with “fire-and-forget”.
Of course, i would advise not to break structured concurrency in the first place.
r
So you have to explicitly add the job of the current scope as parent as not to commit heresy against structured concurrency?
e
yes but then you also keep the parent job alive as long as the child is running, which makes it effectively the same as
supervisorScope {}
z
Also launch does that itself, so if you dont want to violate SC then just don’t pass a job at all (unless you specifically want the supervisor type)