summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-01-04 18:19:09 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-02-11 14:36:18 +0000
commit75f10ce304c949bbd18850f8b474e39c57278618 (patch)
treea0931dd6234a8a3fba696f7113c01d5b09f48d7b /android/src/main
parent1ec10358c88dfa7e144e7bc185951cda47d5dc1d (diff)
downloadmullvadvpn-75f10ce304c949bbd18850f8b474e39c57278618.tar.xz
mullvadvpn-75f10ce304c949bbd18850f8b474e39c57278618.zip
Add an `Intermittent.spawnUpdate()` helper method
Diffstat (limited to 'android/src/main')
-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()
}