Recently I'm learning to use DAO. From what I understand, all the @Insert, @Update, or @Query are executed asynchronously. And from the documentary, @Insert can return a long value, which is the new rowId for the inserted item (or List<long> if multiple items). Assuming my DAO looks like this:
@Insert
long insertTransaction(Transaction transaction);
@Insert
List<Long> insertTransactions(List<Transaction> transactions);
When I use these methods in an activity or fragment, does it mean I get the long value after the async task is completed?
<!-- language: lang-none -->
// Do I get 0 if the insert is not complete
// or it will wait till the insert is complete and return long?
long id = viewModel.insertTransaction(transaction)
If it waits for the async task to finish, won't it block the main thread (especially when inserting large lists)? And if not, how do I check if the insert is finished?