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

nwh

10/09/2018, 8:58 PM
Is passing the
ctx
to the
launch
method redundant in this scenario?
Copy code
val ctx = newSingleThreadContext("sample")
val scope = CoroutineScope(ctx)
scope.launch(ctx) { }
l

louiscad

10/09/2018, 10:02 PM
Yes it is. It will no-op because it's the same
v

voddan

10/10/2018, 8:35 AM
Why does
launch
accepts an optional context then? Can't the API be minimized to always use the scopes?
l

louiscad

10/10/2018, 8:44 AM
The additional and optional
CoroutineContext
is folded with the context from the scope. That gives you structured concurrency, but you can still launch in another dispatcher, or add something to the scope's context.
12 Views