diff options
| author | David Göransson <david.goransson@mullvad.net> | 2025-03-03 23:10:19 +0100 |
|---|---|---|
| committer | David Göransson <david.goransson@mullvad.net> | 2025-03-03 23:10:19 +0100 |
| commit | f31658c25760b796dd2775fcdbf7d8b980618d9d (patch) | |
| tree | cff01ab58fafdd6da6402f2b9f0056584516109f /android/lib/common | |
| parent | 0199b5872f8268a7017aa202c309b50dafe2c704 (diff) | |
| parent | 9eb15e878f8a5aec1cb0963d33b1492308b6a4f7 (diff) | |
| download | mullvadvpn-f31658c25760b796dd2775fcdbf7d8b980618d9d.tar.xz mullvadvpn-f31658c25760b796dd2775fcdbf7d8b980618d9d.zip | |
Merge branch 'fix-broken-connectivitylistener-on-main-branch-droid-1856'
Diffstat (limited to 'android/lib/common')
| -rw-r--r-- | android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonFlowUtils.kt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonFlowUtils.kt b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonFlowUtils.kt index bf94c80778..863fc32251 100644 --- a/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonFlowUtils.kt +++ b/android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/CommonFlowUtils.kt @@ -1,9 +1,26 @@ package net.mullvad.mullvadvpn.lib.common.util +import kotlin.time.Duration +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.withIndex import kotlinx.coroutines.withTimeoutOrNull suspend fun <T> Flow<T>.firstOrNullWithTimeout(timeMillis: Long): T? { return withTimeoutOrNull(timeMillis) { firstOrNull() } } + +@OptIn(FlowPreview::class) +fun <T> Flow<T>.debounceFirst(timeout: Duration): Flow<T> = + withIndex() + .debounce { + if (it.index == 0) { + timeout + } else { + Duration.ZERO + } + } + .map { it.value } |
