File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
app/src/main/java/to/bitkit/repositories Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.first
1717import kotlinx.coroutines.flow.update
1818import kotlinx.coroutines.tasks.await
1919import kotlinx.coroutines.withContext
20+ import kotlinx.coroutines.withTimeout
2021import kotlinx.coroutines.withTimeoutOrNull
2122import org.lightningdevkit.ldknode.Address
2223import org.lightningdevkit.ldknode.BalanceDetails
@@ -57,6 +58,8 @@ import kotlin.time.Duration
5758import kotlin.time.Duration.Companion.minutes
5859import kotlin.time.Duration.Companion.seconds
5960
61+ private const val SYNC_TIMEOUT_MS = 10_000L
62+
6063@Singleton
6164class LightningRepo @Inject constructor(
6265 @BgDispatcher private val bgDispatcher : CoroutineDispatcher ,
@@ -260,7 +263,10 @@ class LightningRepo @Inject constructor(
260263 if (_lightningState .value.isSyncingWallet) {
261264 Logger .warn(" Sync already in progress, waiting for existing sync." , context = TAG )
262265 }
263- _lightningState .first { ! it.isSyncingWallet }
266+
267+ withTimeout(SYNC_TIMEOUT_MS ) {
268+ _lightningState .first { ! it.isSyncingWallet }
269+ }
264270
265271 _lightningState .update { it.copy(isSyncingWallet = true ) }
266272 lightningService.sync()
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import com.synonym.bitkitcore.decode
66import kotlinx.coroutines.CoroutineDispatcher
77import kotlinx.coroutines.CoroutineScope
88import kotlinx.coroutines.SupervisorJob
9+ import kotlinx.coroutines.TimeoutCancellationException
910import kotlinx.coroutines.flow.MutableStateFlow
1011import kotlinx.coroutines.flow.asStateFlow
1112import kotlinx.coroutines.flow.filter
@@ -152,6 +153,9 @@ class WalletRepo @Inject constructor(
152153 syncBalances()
153154 return @withContext Result .success(Unit )
154155 }.onFailure { e ->
156+ if (e is TimeoutCancellationException ) {
157+ syncBalances()
158+ }
155159 return @withContext Result .failure(e)
156160 }
157161 }
You can’t perform that action at this time.
0 commit comments