Skip to content

Commit f7197a9

Browse files
committed
[ECO-5076] Updated impl. to dispose objects using ablyexception
1 parent 6d20ffe commit f7197a9

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

live-objects/src/main/kotlin/io/ably/lib/objects/DefaultLiveObjects.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.ably.lib.objects
33
import io.ably.lib.objects.state.ObjectsStateChange
44
import io.ably.lib.objects.state.ObjectsStateEvent
55
import io.ably.lib.realtime.ChannelState
6+
import io.ably.lib.types.AblyException
67
import io.ably.lib.types.Callback
78
import io.ably.lib.types.ProtocolMessage
89
import io.ably.lib.util.Log
@@ -189,12 +190,12 @@ internal class DefaultLiveObjects(internal val channelName: String, internal val
189190
}
190191

191192
// Dispose of any resources associated with this LiveObjects instance
192-
fun dispose(reason: String) {
193-
val cancellationError = CancellationException("Objects disposed for channel $channelName, reason: $reason")
194-
incomingObjectsHandler.cancel(cancellationError) // objectsEventBus automatically garbage collected when collector is cancelled
193+
fun dispose(cause: AblyException) {
194+
val disposeReason = CancellationException().apply { initCause(cause) }
195+
incomingObjectsHandler.cancel(disposeReason) // objectsEventBus automatically garbage collected when collector is cancelled
195196
objectsPool.dispose()
196197
objectsManager.dispose()
197-
// Don't cancel sequentialScope (needed in public methods), just cancel ongoing coroutines
198-
sequentialScope.coroutineContext.cancelChildren(cancellationError)
198+
// Don't cancel sequentialScope (needed in getRoot method), just cancel ongoing coroutines
199+
sequentialScope.coroutineContext.cancelChildren(disposeReason)
199200
}
200201
}

live-objects/src/main/kotlin/io/ably/lib/objects/DefaultLiveObjectsPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public class DefaultLiveObjectsPlugin(private val adapter: LiveObjectsAdapter) :
2222
}
2323

2424
override fun dispose(channelName: String) {
25-
liveObjects[channelName]?.dispose("Channel has ben released using channels.release()")
25+
liveObjects[channelName]?.dispose(clientError("Channel has ben released using channels.release()"))
2626
liveObjects.remove(channelName)
2727
}
2828

2929
override fun dispose() {
3030
liveObjects.values.forEach {
31-
it.dispose("AblyClient has been closed using client.close()")
31+
it.dispose(clientError("AblyClient has been closed using client.close()"))
3232
}
3333
liveObjects.clear()
3434
}

0 commit comments

Comments
 (0)