Skip to content

Commit

Permalink
Clean up retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Oct 13, 2023
1 parent eb9cbfc commit 06e91a2
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,17 @@ class FafLobbyClient(
is LoginSuccessResponse -> Mono.just(it.me)
is LoginFailedResponse -> Mono.error(LoginException(it.text))
}
}.timeout(outboundMessages.ofType(SessionRequest::class.java)
.next()
.then(Mono.delay(Duration.ofSeconds(10)))
.timeout(Duration.ofMinutes(1), Mono.empty()))
}.timeout(Duration.ofSeconds(10))
.doOnError(LoginException::class.java) { kicked = true }
.doFirst {
prepareAuthenticateOnNextSession()
send(SessionRequest(config.version, config.userAgent))
}

private val loginMono = Mono.defer {
connectionAcquired.next().then(loginResponseMono.retryWhen(createRetrySpec(config))).doFirst {
connectionDisposable?.dispose()
connectionDisposable = openConnection()
}
connectionAcquired.next().then(loginResponseMono).doFirst {
openConnection()
}.retryWhen(createRetrySpec(config))
}
.doOnError { LOG.error("Error during connection", it); connection?.dispose() }
.doOnCancel { LOG.debug("Login cancelled"); disconnect() }
Expand Down Expand Up @@ -154,9 +150,10 @@ class FafLobbyClient(
}.subscribe()
}

private fun openConnection(): Disposable {
private fun openConnection() {
LOG.debug("Opening connection")
return webSocketClient
connectionDisposable?.dispose()
connectionDisposable = webSocketClient
.uri(config.url)
.handle { inbound, outbound ->
val inboundMono = inbound.receive()
Expand Down

0 comments on commit 06e91a2

Please sign in to comment.