https://kotlinlang.org logo
#android
Title
# android
a

android.zeeshan

07/08/2019, 9:54 PM
Should I use doAsync or Coroutines with Room ? Which one is better and why ? I have used doAsync with Room that works fine for so far.
g

gildor

07/09/2019, 1:03 AM
If you use coroutines in your app, use Coroutines, if you don’t just use doAsync I don’t think that just Room API is real reason to use coroutines, you should understand yourself, do you need coroutines or not, and not only for one API of your app
t

treatmaster

07/09/2019, 9:31 AM
let think about what happen with complex query that takes long time than 5ms
g

gildor

07/09/2019, 9:59 AM
huh, you know what, I just now realized that doAsync is not some Room thing, but function from Anko? Isn’t it?
If so, I would use coroutines, because doAsync is just wrapper for thread pool
👍 2
So if it works for you fine, price of creation of new thread is not so high in case of real app, but in general don’t think that I would ever use it
a

android.zeeshan

07/09/2019, 4:54 PM
But with Coroutines, will it also not create new thread same like created in doAsync ? @gildor I am Novice in Coroutines. Sorry for basic questions.
Thanks for your time and replies
g

gildor

07/09/2019, 11:33 PM
It's a bit more complicated question, because with coroutines under the hood Room still uses own thread pool to dispatch requests. Bu in theory room may reuse this thread, or already create it under the hood, but with doAsync you always create new thread.
2 Views