Hey guys, I've a question regarding best practices...
# android
d
Hey guys, I've a question regarding best practices on where should the thread switching to background (ie. coroutines context switching Dispatchers.IO) take place in a clean architecture app? Should that take place inside the Repository (in the data layer), or in the UseCase-s (domain layer)? Would really hope to hear your opinions on that with some Advantages / disadvantages presented.
👍 1
m
Both Google and JetBrains recommends all suspend functions to be main safe. If you follow that, then you can call all suspend functions from the main thread. In general I would switch to background thread at the point where you will be blocking the coroutine instead of suspending it.
☝️ 2
p
@mkrussel do you have a link for that?
d
I was curious on the point where this thread switching (or withContext(Dispatcher.IO) in case of coroutines) should take place. I was thinking about doing that at the Repository level, but calling multiple functions from the Repo in the UseCase would inefficiently switch threads to IO and back for each call.