matt tighe
09/06/2018, 6:13 PMfun refreshData() {
networkStatus = Status.ACTIVE // class member
launch(CommonPool) {
asyncAwait {
remoteSource.fetchData().forEach {
roomDatabase.dao().insertData(it)
}
networkStatus = Status.INACTIVE
}
}
}
i’d like to be able to unit test that the status is updated while the coroutine is runningJonathan Walsh
09/06/2018, 6:21 PMJonathan Walsh
09/06/2018, 6:21 PMJonathan Walsh
09/06/2018, 6:21 PMDico
09/06/2018, 8:49 PMrunBlocking {
remoteSource.fetchData().forEach {
roomDatabase.dao().insertData(it)
}
networkStatus = Status.INACTIVE
}
Dico
09/06/2018, 8:49 PMDico
09/06/2018, 8:50 PMlaunch {
// code here
}.join()
gildor
09/07/2018, 1:44 AMasyncAwait
? Shortcut for async{}.await()? If so, it doesn’t make any sense, there are not cases when you call async{} and await immidiately. Probably you can just call the function or use withContext insteadgildor
09/07/2018, 1:44 AMCommonPool
in probably redundantgildor
09/07/2018, 1:47 AMlaunch(CommonPool)
and asyncAwait
so it allows you to wait (suspend) until function finish and check side effect after
It’s exactly the same bad style as launch thread in a function: you just cannot test it and have other problems with lifecycle of such function, concurrent updates and so ongildor
09/07/2018, 2:42 AMwithContext(IO)
).
or use async API of Room (there are adapters for RxJava and LiveData)gildor
09/07/2018, 2:46 AMDico
09/07/2018, 8:36 AMDico
09/07/2018, 8:37 AM