jean
01/10/2023, 2:19 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
but my concern is on the coroutine scope. Does Room guarantee inserts or is it possible that it doesn’t go through if the insert is done from a viewModelScope
for example and the view is destroyed at the same time? Should I even consider using WorkManager
to be sure my inserts work even if the app is killed?bezrukov
01/10/2023, 2:34 PMDoes Room guarantee inserts or is it possible that it doesn’t go through if the insert is done from aNo, it doesn't guarantee insert if vmScope gets cancelled. You can wrap your insert intofor example and the view is destroyed at the same time?viewModelScope
withContext(NonCancellable)
for this particular case if you want it to be inserted regardless of VM's scope cancellation. Another option is to launch it in a wider scope (e.g. app scope).
Both options won't help in case of process' death (I don't think you have anything to do with it)
Should I even consider usingI don't think so because of how WM works under the hood. Internally it uses Room DB as well, that means your work is asynchronously persisted to the library table. That means it also won't help if process is dying during insert transaction.to be sure my inserts work even if the app is killed? (edited)WorkManager
jean
01/10/2023, 6:21 PM