mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 08:15:02 +00:00
Release room list entries resources even if onControllerCreated is cancelled
Use try/finally instead of the awaitClose block, so that the entries stream, the controller and the dynamic adapters are destroyed even if the suspending onControllerCreated callback is cancelled or throws before awaitClose is reached. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+7
-3
@@ -70,9 +70,13 @@ internal fun RoomListInterface.entriesFlow(
|
||||
listener = listener,
|
||||
)
|
||||
val controller = result.controller()
|
||||
controller.setFilter(initialFilterKind)
|
||||
onControllerCreated(controller)
|
||||
awaitClose {
|
||||
// Use try/finally rather than awaitClose's block, so that the resources are released even if
|
||||
// onControllerCreated is cancelled or throws before awaitClose is reached
|
||||
try {
|
||||
controller.setFilter(initialFilterKind)
|
||||
onControllerCreated(controller)
|
||||
awaitClose()
|
||||
} finally {
|
||||
result.entriesStream().cancelAndDestroy()
|
||||
controller.destroy()
|
||||
result.destroy()
|
||||
|
||||
Reference in New Issue
Block a user