Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ internal class Connection(
on(webSocketOpen()) {
transitionTo(Connected(session = session))
}
on(lifecycleStop()) {
initiateShutdown(it.state)
transitionTo(Disconnecting)
}
on<OnWebSocket.Terminate>() {
val backoffDuration = backoffStrategy.backoffDurationMillisAt(retryCount)
val timerDisposable = scheduleRetry(backoffDuration)
Expand Down Expand Up @@ -204,6 +208,13 @@ internal class Connection(
}
}

private fun Connecting.initiateShutdown(state: Lifecycle.State) {
when (state) {
is Lifecycle.State.Stopped.WithReason -> session.webSocket.close(state.shutdownReason)
Lifecycle.State.Stopped.AndAborted -> session.webSocket.cancel()
}
}

private fun WaitingToRetry.cancelRetry() = timerDisposable.dispose()

private fun lifecycleStart() =
Expand Down