How do you know wether you use Dispatchers.Default...
# coroutines
p
How do you know wether you use Dispatchers.Default on Android side? In terms of mapping objects? If it's a 1:1 mapper is it really needed to use withContext(Dispatchers.Default)? I thought that it's needed when you need to do heavy operations like sorting, etc..?
m
Dispatchers.Default
is really tricky one. Use it with caution. You should
Dispatchers.Default
handle the same number of operations as number of cores on the device. If you have more you will wait for one of them to finish in order to do another one. On low spec devices that could be only 2 operations. You shouldn’t really have problems here but just keep this in mind
If you start running into problems it’s better to implement your own unbound
Dispatcher
than to use
Dispatchers.Default
Also single thread dispatcher is more than enough for most apps. I don’t know how heavy is the sorting you need to do, if that’s not just an example, but it should work
p
Nono, mine it's not hard but I'm wondering if someday I need to do a super heavy sorting, and stuff like requieres a lot of CPU then I'd use Dispatchers.Default?
When you talk about a single thread dispatcher what do you mean?
m
your dispatcher will use a single thread.
<http://Dispatcher.IO|Dispatcher.IO>
for example, same for
Dispatcher.Default
, can start coroutine one one thread and finish it on some other thread. this dispatcher use just one thread