File tree Expand file tree Collapse file tree
live-objects/src/main/kotlin/io/ably/lib/objects Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package io.ably.lib.objects
22
33import io.ably.lib.realtime.CompletionListener
4+ import io.ably.lib.types.AblyException
45import io.ably.lib.types.ErrorInfo
56import io.ably.lib.types.ProtocolMessage
6- import kotlinx.coroutines.CompletableDeferred
7+ import kotlinx.coroutines.suspendCancellableCoroutine
8+ import kotlin.coroutines.resume
9+ import kotlin.coroutines.resumeWithException
710
8- internal suspend fun LiveObjectsAdapter.sendAsync (message : ProtocolMessage ) {
9- val deferred = CompletableDeferred <Unit >()
11+ internal suspend fun LiveObjectsAdapter.sendAsync (message : ProtocolMessage ) = suspendCancellableCoroutine { continuation ->
1012 try {
1113 this .send(message, object : CompletionListener {
1214 override fun onSuccess () {
13- deferred.complete (Unit )
15+ continuation.resume (Unit )
1416 }
1517
1618 override fun onError (reason : ErrorInfo ) {
17- deferred.completeExceptionally( Exception (reason.message ))
19+ continuation.resumeWithException( AblyException .fromErrorInfo (reason))
1820 }
1921 })
2022 } catch (e: Exception ) {
21- deferred.completeExceptionally (e)
23+ continuation.resumeWithException (e)
2224 }
23- deferred.await()
2425}
2526
2627internal enum class ProtocolMessageFormat (private val value : String ) {
You can’t perform that action at this time.
0 commit comments