summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/util/Intermittent.kt15
1 files changed, 10 insertions, 5 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/util/Intermittent.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/util/Intermittent.kt
index 15e39d7c19..864667700c 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/util/Intermittent.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/util/Intermittent.kt
@@ -62,11 +62,8 @@ class Intermittent<T> {
}
}
- // Helper method that provides a simple way to change the wrapped value.
- //
- // The method returns a property delegate that will spawn a coroutine to update the wrapped
- // value every time the property is written to.
- fun source() = observable<T?>(null) { _, _, newValue ->
+ // Helper method that spawns a coroutine to update the value.
+ fun spawnUpdate(newValue: T?) {
synchronized(this@Intermittent) {
val previousUpdate = updateJob
@@ -77,6 +74,14 @@ class Intermittent<T> {
}
}
+ // Helper method that provides a simple way to change the wrapped value.
+ //
+ // The method returns a property delegate that will spawn a coroutine to update the wrapped
+ // value every time the property is written to.
+ fun source() = observable<T?>(null) { _, _, newValue ->
+ spawnUpdate(newValue)
+ }
+
fun onDestroy() {
notifier.unsubscribeAll()
}