natario1
01/19/2022, 4:30 PMval data: Flow<String?> = ....
val hasData: Flow<Boolean> = data.map { it != null }
val combined = data.combine(hasData) { data, hasData ->
require(data == null || hasData)
}
Note that hasData does not suspend, and let's assume flow will be collected on a single thread dispatcher.ephemient
01/19/2022, 4:39 PMdata
twice, which seems unlikely to be what you want - nothing ensures the two collectors are in sync with each othernatario1
01/19/2022, 4:47 PMdata
is shared so it should be fine. I know it's ugly, I'll change this at some point - for now I'm trying to debug an issue and wanted to rule this outTrevor Stone
01/19/2022, 5:39 PMzip
instead of combine hereNick Allen
01/19/2022, 5:40 PMFlow
is sequential. Multiple flows, however, are not and can be collected concurrently and there are no guarantees that they will be collected at a similar pace. In your example, data
and hasData
could be inconsistent.Trevor Stone
01/19/2022, 5:59 PM