reactormonk
09/26/2024, 4:25 PMval received = withTimeoutOrNull(TvOnTimeout) {
tvState.first()
}
irBlaster.send(commandToTest)
I wanna wait for the next tvState
, but start to wait for that change before sending the command via irBlaster
. How do I wire them up?Sergey Dmitriev
09/26/2024, 4:28 PMtvState
that comes after received
?reactormonk
09/26/2024, 4:29 PMtvState
, and I wanna know if that happens within a certain timeout.Sergey Dmitriev
09/26/2024, 4:31 PMreceived
?
Because then you can do tvState.first { it == expectedState }.timeout()
reactormonk
09/26/2024, 4:31 PMreactormonk
09/26/2024, 4:31 PMval tvState = cecFlows.tvState
.filter { it is TVState.Standby || it is TVState.TransientToStandby }
val received = withTimeoutOrNull(TvStandbyTimeout) {
tvState.first()
}
reactormonk
09/26/2024, 4:32 PMSergey Dmitriev
09/26/2024, 4:33 PMSergey Dmitriev
09/26/2024, 4:34 PMexpectedState == receivedState
reactormonk
09/26/2024, 4:44 PMtimeout
from? Can't import itSergey Dmitriev
09/26/2024, 4:49 PMfirst
is a terminate operator so it’s either return the expected value or waits forever…
you can try
tvState.filter { it == expected }.timeout().first()
Or something similarreactormonk
09/26/2024, 4:53 PMSergey Dmitriev
09/26/2024, 4:54 PMreactormonk
09/26/2024, 4:57 PMsend
, and continue waitingreactormonk
09/26/2024, 4:58 PMval wait = Channel<Unit>(RENDEZVOUS)
launch {
irBlaster.send(commandToTest)
wait.send(Unit)
}
wait.receive()
val received = withTimeoutOrNull(TvOnTimeout) {
cecFlows.tvState.first { it is TVState.Standby || it is TVState.TransientToStandby }
}
This should doreactormonk
09/26/2024, 4:59 PMSam
09/27/2024, 7:10 AMtvState
a StateFlow
? If so, I think onSubscription
has the behavior you're looking for:
tvState
.onSubsbscription { irBlaster.send(commandToTest) }
.first { it is TVState.Standby || it is TVState.TransientToStandby }
Sam
09/27/2024, 7:11 AMThe action is called before any value is emitted from the upstream flow to this subscription but after the subscription is established. It is guaranteed that all emissions to the upstream flow that happen inside or immediately after this onSubscription action will be collected by this subscription.Which sounds similar to
I wanna wait for the nextvery nice, but start to wait for that change before sending the command viatvState
.irBlaster