reactormonk
09/20/2022, 4:00 PMfun onReaderConnected(): Flow<Reader> { ... }
class Reader {
fun onCard(): Flow<Card>
}
And I'm consuming it via
onReaderConnected() { reader ->
reader.onCard().collect {
... process card ...
}
}
Now I've run into the issue where the reader disconnects, the inner collect
won't stop, so the new reader connection won't get activated. How do I best model that?simon.vergauwen
09/20/2022, 4:05 PMflatMap
in this case? 🤔
val x: Flow<Unit> = onReaderConnected().flatMapConcat {
reader.onCard().map {
/** process card */
}
}
Or flatMapLatest
based on desired behaviorsimon.vergauwen
09/20/2022, 4:05 PMcollect()
or launchIn
at the edge.reactormonk
09/20/2022, 4:09 PMflatMapLatest
looks exactly what I'm looking for, thanks! Now to figure out why it doesn't behave as it should 🤔louiscad
09/21/2022, 7:40 AM