vineethraj49
11/06/2019, 8:42 AMasync(Dispatchers.Default)
on runBlocking
) ok, or will this blow up in my face?octylFractal
11/06/2019, 8:44 AM<http://Dispatchers.IO|Dispatchers.IO>
for better coroutine integrationvineethraj49
11/06/2019, 8:45 AMrunMany
has some blocking loadUrl
calls, defined as such:
suspend fun loadUrl(url: String) = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
...}
vineethraj49
11/06/2019, 8:46 AMsuspend fun runMany(): List<String> = coroutineScope {
...
val one = async { loadUrl() }
val two = async { loadUrl() }
return listOf(one.await(), two.await())
}
vineethraj49
11/06/2019, 8:47 AMrunMany
is in Dispatchers.Default
, the suspended loadUrl
inside is on <http://Dispatchers.IO|Dispatchers.IO>
vineethraj49
11/06/2019, 8:49 AMDefaultDispatcher
(which “shares threads with a [Default][Dispatchers.Default]“) or will the calls on Dispatchers.IO suspend and give back the threads to Dispatchers.Default?vineethraj49
11/06/2019, 8:50 AMfun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
with -Dkotlinx.coroutines.debug
enabledoctylFractal
11/06/2019, 8:53 AMcoroutineContext[ContinuationInterceptor]
2. you won't starve the default dispatcher afaik, not sure how the specifics work outoctylFractal
11/06/2019, 8:54 AMbdawg.io
11/06/2019, 9:14 AM