Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Fix cancelling/retrying conversation connection on ios
Browse files Browse the repository at this point in the history
mklkj committed Mar 11, 2024
1 parent caf34ac commit 89a23a8
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@ import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.uuid.UUID
import org.koin.core.annotation.Factory
import kotlin.coroutines.cancellation.CancellationException
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

@@ -106,11 +105,8 @@ class ConversationClient(
connectionStatus.update { ConnectionStatus.Connecting }
chatSession = runCatching { messagesRepository.getChatSession(chatId) }
.onFailure { error ->
Logger.e("Error while connecting to websocket", error)
connectionStatus.update { ConnectionStatus.Error(error) }
if (error !is CancellationException) {
isConnectionShouldRetry.send(true)
}
isConnectionShouldRetry.send(true)
}
.onSuccess {
connectionStatus.update { ConnectionStatus.Connected }
@@ -125,14 +121,8 @@ class ConversationClient(
}
}
?.catch { error ->
Logger.e("Error while observing incoming messages from websocket", error)
chatSession = null

// workaround for non-cancelling job when composition exit
// probably related to https://github.com/Kotlin/kotlinx.coroutines/issues/2521
if (error !is CancellationException) {
isConnectionShouldRetry.send(true)
}
isConnectionShouldRetry.send(true)
connectionStatus.update { ConnectionStatus.Error(error) }
}
?.collect()
@@ -246,5 +236,6 @@ class ConversationClient(

fun onDispose() {
chatSession?.cancel()
scope.cancel()
}
}

0 comments on commit 89a23a8

Please sign in to comment.