Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Dohan committed Aug 27, 2024
1 parent f78b6ac commit 4a77432
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package renetik.android.event.registration
import kotlinx.coroutines.suspendCancellableCoroutine
import renetik.android.core.lang.Func
import renetik.android.core.lang.Quadruple
import renetik.android.core.lang.value.CSValue
import renetik.android.event.common.CSLaterOnceFunc.Companion.laterOnceFunc

suspend fun <T> CSHasChange<T>.waitForChange(): T =
Expand All @@ -19,12 +20,18 @@ suspend fun <T> CSHasChange<T>.waitForChange(): T =
infix fun CSHasChange<*>.or(other: CSHasChange<*>): CSHasChange<Unit> {
val self = this
return object : CSHasChange<Unit> {
override fun onChange(function: (Unit) -> Unit): CSRegistration {
return CSRegistration(
self.onChange { function(Unit) },
other.onChange { function(Unit) },
)
}
override fun onChange(function: (Unit) -> Unit) = CSRegistration(
self.onChange { function(Unit) },
other.onChange { function(Unit) },
)
}
}

infix fun CSHasChange<*>.and(other: CSValue<Boolean>): CSHasChange<Unit> {
val self = this
return object : CSHasChange<Unit> {
override fun onChange(function: (Unit) -> Unit): CSRegistration =
CSRegistration(self.onChange { if (other.value) function(Unit) })
}
}

Expand Down

0 comments on commit 4a77432

Please sign in to comment.