ansman
02/27/2019, 1:59 PMcoroutineScope
doesn’t accept a CoroutineContext
to merge with the parent context?louiscad
02/27/2019, 2:19 PMCoroutineScope
?
You need to use withContext
, and the CoroutineScope
receiver of the passed lamba will have the merged coroutineContext
.ansman
02/27/2019, 2:20 PMcoroutineScope
. Wanting to do structured concurrency on a specific dispatcher requires this:
coroutineScope {
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
...
}
}
coroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
louiscad
02/27/2019, 2:21 PMcoroutineScope
in that case. Using withContext
is exactly what you need.ansman
02/27/2019, 2:22 PMwithContext
creates a scopelouiscad
02/27/2019, 2:23 PMcoroutineScope
to be an alias to withContext
could make sense, although it would be the very same thing. Which naming would you prefer, and why?Dico
02/27/2019, 2:31 PMcoroutineScope
and withContext
have different semantics in terms of structured concurrencygildor
02/27/2019, 3:30 PMelizarov
02/27/2019, 7:14 PMwithContext { ... }
without parameters does not look right either.Dico
02/27/2019, 7:19 PMelizarov
02/27/2019, 7:21 PMwithContext
does more things to figure out if you are actually changing context.Dico
02/27/2019, 7:23 PMgildor
02/28/2019, 12:17 AMawaitScope
, we already have awaitAll
, where we pass vararg of Deferred, in this case we pass lambda with receiver that becomes CoroutineScope. Not perfect semantically, but clear that this call will suspend until scope is activeansman
02/28/2019, 6:06 PMcoroutineScope(context)
gildor
03/01/2019, 1:44 AMcoroutineScope(context)
? To replace withCcontext? It’s counterintuitive imo, withContext is better name that run some block with passed context, it was there before StructuredConcurrency and scopes