Skip to content

Commit

Permalink
Fix timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Nov 21, 2023
1 parent e2d5d94 commit 82358ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ inline fun <T1, T2, T3, T4, T5, T6, T7, T8, R> combine(

suspend inline fun <T> Deferred<T>.awaitWithTimeoutOrNull(timeout: Long) =
withTimeoutOrNull(timeout) { await() }

fun <T> Deferred<T>.getOrDefault(default: T) =
try {
getCompleted()
} catch (e: IllegalStateException) {
default
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import net.mullvad.mullvadvpn.repository.AccountRepository
import net.mullvad.mullvadvpn.repository.DeviceRepository
import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
import net.mullvad.mullvadvpn.util.awaitWithTimeoutOrNull
import net.mullvad.mullvadvpn.util.getOrDefault

private const val MINIMUM_LOADING_SPINNER_TIME_MILLIS = 500L

Expand Down Expand Up @@ -101,8 +102,8 @@ class LoginViewModel(
.first()
}
delay(1000)
val outOfTime = isOutOfTimeDeferred.awaitWithTimeoutOrNull(200)
if (outOfTime == true) {
val isOutOfTime = isOutOfTimeDeferred.getOrDefault(false)
if (isOutOfTime) {
_uiSideEffect.emit(LoginUiSideEffect.NavigateToOutOfTime)
} else {
_uiSideEffect.emit(LoginUiSideEffect.NavigateToConnect)
Expand Down

0 comments on commit 82358ba

Please sign in to comment.