Skip to content

Commit ea15abc

Browse files
committed
Apply withContext with default dispatcher on the whole rename method
1 parent 2702ba7 commit ea15abc

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

app/src/main/kotlin/at/bitfire/davdroid/repository/AccountRepository.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class AccountRepository @Inject constructor(
179179
* @throws IllegalArgumentException if the new account name already exists
180180
* @throws Exception (or sub-classes) on other errors
181181
*/
182-
suspend fun rename(oldName: String, newName: String) {
182+
suspend fun rename(oldName: String, newName: String): Unit = withContext(defaultDispatcher) {
183183
val oldAccount = fromName(oldName)
184184
val newAccount = fromName(newName)
185185

@@ -201,13 +201,10 @@ class AccountRepository @Inject constructor(
201201
// rename account (also moves AccountSettings)
202202
val future = accountManager.renameAccount(oldAccount, newName, null, null)
203203

204-
// wait for operation to complete
205-
withContext(defaultDispatcher) {
206-
// blocks calling thread
207-
val newNameFromApi: Account = future.result
208-
if (newNameFromApi.name != newName)
209-
throw IllegalStateException("renameAccount returned ${newNameFromApi.name} instead of $newName")
210-
}
204+
// wait for operation to complete (blocks calling thread)
205+
val newNameFromApi: Account = future.result
206+
if (newNameFromApi.name != newName)
207+
throw IllegalStateException("renameAccount returned ${newNameFromApi.name} instead of $newName")
211208

212209
// account renamed, cancel maybe running synchronization of old account
213210
syncWorkerManager.get().cancelAllWork(oldAccount)
@@ -242,9 +239,7 @@ class AccountRepository @Inject constructor(
242239
}
243240

244241
// update automatic sync
245-
withContext(defaultDispatcher) {
246-
automaticSyncManager.get().updateAutomaticSync(newAccount)
247-
}
242+
automaticSyncManager.get().updateAutomaticSync(newAccount)
248243
} finally {
249244
// release AccountsCleanupWorker mutex at the end of this async coroutine
250245
AccountsCleanupWorker.unlockAccountsCleanup()

0 commit comments

Comments
 (0)