what dispatcher are you guys using for IO operatio...
# coroutines
i
what dispatcher are you guys using for IO operations on Android? If someone use a custom one with a pool, how many threads are you using in the pool? Thanks in advance
@louiscad Looks good. But for curiosity, I want a dispatcher for my
useCases
(or interactors), but I'm not sure what to use. I was thinking about using my custom pool, but I'm not sure how many threads it would have. Maybe I can use yours IO dispatcher, and if my usecases do any cpu bound operations, switch to another context. What do you think about that? Thanks in advance.
l
@igorvd I personally use this already configured
ioDispatcher
, and use
CommonPool
for CPU bound operations, unless it's not worth switching dispatcher for a short operation in a coroutine already running on a background thread.
i
>> unless it's not worth switching
How do I know that is not worth? Is this approach working fine for you? Are you experiencing any lazyness because of threads waiting the pool become available?
Sorry for so many questions! Thank you 😃
l
@igorvd Very very lightweight operations can happen on any thread (UI, CommonPool, ioDispatcher...). Examples are a single integer multiplication, a low frequency allocation (in order to not block the UI thread for too long and avoid dropping frames). Short CPU bound operations can happen on both CommonPool and ioDispatcher (anything non UI thread). By short, I mean less than a second, or even less than half a second. Longer CPU bound operations should happen on CommonPool only. Any I/O operations should happen on ioDispatcher or other non UI thread, but not CommonPool so CPU bound operations are never stuck waiting for I/O.
i
@louiscad thanks man, I get it and I'll probably follow your approach