Lilly
09/21/2023, 11:44 AMsingleOrNull()/firstOrNull()
that does not suspend until first item is emitted? My use case:
suspend fun execute(dispatcher: Coroutines.Dispatcher) {
withContext(dispatcher) {
// do something that returns result
// also process outstanding tasks from SharedFlow<() -> Unit>
outStandingTask.state.singleOrNull()?.invoke() // suspends, so no result is returned
return result
}
}
Would a simple Queue fit better?mkrussel
09/21/2023, 11:48 AMoutstandingTask.state
?Lilly
09/21/2023, 11:49 AMSharedFlow<() -> Unit>
mkrussel
09/21/2023, 11:55 AMstate
, then a queue might be a better fit. Polling a flow is uncommon. If you are polling multiple flows, then using channels and a select call might be better.Lilly
09/21/2023, 11:56 AM