Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan-Cerovsky committed Nov 28, 2024
1 parent 2a5a314 commit 90ddfb8
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ class AddressBookRepositoryImpl(
)
}

override suspend fun deleteContact(contact: AddressBookContact) = mutateAddressBook {
Twig.info { "Address Book: deleting a contact" }
localAddressBookDataSource.deleteContact(
addressBookContact = contact,
addressBookKey = getAddressBookKey()
)
}
override suspend fun deleteContact(contact: AddressBookContact) =
mutateAddressBook {
Twig.info { "Address Book: deleting a contact" }
localAddressBookDataSource.deleteContact(
addressBookContact = contact,
addressBookKey = getAddressBookKey()
)
}

override suspend fun resetAddressBook() =
withNonCancellableSemaphore {
Expand All @@ -107,11 +108,12 @@ class AddressBookRepositoryImpl(
}
}

private suspend fun mutateAddressBook(block: suspend () -> AddressBook) = withNonCancellableSemaphore {
ensureSynchronization()
val newAddressBook = block()
addressBookCache.update { newAddressBook }
}
private suspend fun mutateAddressBook(block: suspend () -> AddressBook) =
withNonCancellableSemaphore {
ensureSynchronization()
val newAddressBook = block()
addressBookCache.update { newAddressBook }
}

private suspend fun withNonCancellableSemaphore(block: suspend () -> Unit) =
withContext(NonCancellable + Dispatchers.Default) {
Expand Down

0 comments on commit 90ddfb8

Please sign in to comment.