vineethraj49
11/05/2019, 12:57 AMtest1()
and test2()
end up doing the same? (my guess: yes)
test1: async(<http://Dispatchers.IO|Dispatchers.IO>) { [...] }
test2: suspend fun logic() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { [...] }; async { logic() }
if so, which is more idiomatic?streetsofboston
11/05/2019, 1:07 AMvineethraj49
11/05/2019, 1:10 AMDispatchers.Default
for everything, <http://Dispatchers.IO|Dispatchers.IO>
for my network calls; assuming that,
is spawning CPU intensive workload on Dispatchers.Default
or async(Dispatchers.Default)
1. both bad?
2. both bad, but second slightly worse
3. first is ok, second is notstreetsofboston
11/05/2019, 1:24 AMDefault
is for CPU intensive jobs, the thread pool is pegged to number of CPU cores.
IO
is for code that blocks (network, io in general, code that has Thread.sleep, etc)
Note that they do share threads between their pools, so you won’t get deadlocks (easily).