Hi guys! :slightly_smiling_face: I’m looking to re...
# announcements
j
Hi guys! 🙂 I’m looking to rewrite some of our old Rx code with flow but I just can’t get my head around this one... What I’m looking to do is : collect a flow with a timeout, everytime I collect a value, check if it satisfies a certain condition else keep collecting And I need a way to know if, at the end of the timeout, nothing was collected. I feel like I’m somewhat close with this but it just doesn’t seem to be working like I want 😕
Copy code
val result = withTimeoutOrNull(10000L) {
    flowProvider.getFlow().collect {
        if (it.condition) // ALL GOOD, can exit collect and keep going
        else // Not good enough, collect some more and see if I can get a match
    }
}
if (result) == null // Assume nothing was collected?
Is it even feasible this way?
a
perhaps
.first { it.condition }
instead of
collect
here?
j
Gave it a try but withTimeoutOrNull then seem to exist right away without doing anything 🤔 Also, not sure if relevant but could be. The stream behind the flow is a hot one. Right now, it’s a StateFlow (considering moving it to a SharedFlow but I don’t believe it matters for that specific use case)