Skip to content

Commit

Permalink
Added delay between websocket reconnections.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksey-saenko committed Nov 2, 2023
1 parent 9f838ea commit 5592d0c
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.squareup.moshi.Moshi
import com.squareup.moshi.adapter
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.emitAll
Expand Down Expand Up @@ -43,8 +44,11 @@ class AuddRecognitionWebSocketServiceImpl @Inject constructor(
token: String,
requiredServices: UserPreferencesDo.RequiredServicesDo
): Flow<SocketEvent> = flow {
var reconnectionDelay = 1000L
while (true) {
emitAll(startSingleSession(token, requiredServices))
delay(reconnectionDelay)
if (reconnectionDelay < 4000L) reconnectionDelay *= 2
}
}

Expand Down

0 comments on commit 5592d0c

Please sign in to comment.