Make RustMatrixClient.close asynchronous (#4513)

* Make `RustMatrixClient.close` asynchronous

This is a safer way to destroy the Rust instances associated to it. Since `MatrixClient` doesn't implement `Closeable` anymore, the method has been renamed to `destroy` to follow the existing naming in the project.
This commit is contained in:
Jorge Martin Espinosa 2025-04-02 11:52:37 +02:00 committed by GitHub
parent 2e191de343
commit d7ca529db1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 25 deletions

View file

@ -476,16 +476,13 @@ class RustMatrixClient(
override fun roomDirectoryService(): RoomDirectoryService = roomDirectoryService
override fun close() {
internal suspend fun destroy() {
innerNotificationClient.close()
appCoroutineScope.launch {
roomFactory.destroy()
rustSyncService.destroy()
notificationSettingsService.destroy()
// This is sync, but it can destroy the `Client` instance and block stopping the sync service
notificationProcessSetup.destroy()
}
roomFactory.destroy()
rustSyncService.destroy()
notificationSettingsService.destroy()
notificationProcessSetup.destroy()
sessionCoroutineScope.cancel()
clientDelegateTaskHandle?.cancelAndDestroy()
@ -504,7 +501,7 @@ class RustMatrixClient(
override suspend fun clearCache() {
innerClient.clearCaches()
close()
destroy()
}
override suspend fun logout(userInitiated: Boolean, ignoreSdkError: Boolean) {
@ -527,7 +524,7 @@ class RustMatrixClient(
}
}
}
close()
destroy()
deleteSessionDirectory()
if (userInitiated) {
@ -577,7 +574,7 @@ class RustMatrixClient(
throw it
}
}
close()
destroy()
deleteSessionDirectory()
sessionStore.removeSession(sessionId.value)
}.onFailure {