Maciek07/20/2020, 11:50 AM
Tim Malseed07/20/2020, 11:52 AM
, then I believe
is the operator you’re looking for here
Maciek07/20/2020, 11:54 AM
Tim Malseed07/20/2020, 12:21 PM
, you could try
Kroppeb07/20/2020, 2:14 PM
julian07/20/2020, 4:36 PM
will wait for an emission from both flows. It alone doesn't allow you to race 2 flows and cancel the loser once you have a winner.
would cancel all upstreams once you have a winner.
louiscad07/21/2020, 3:55 AM
where the winner coroutine cancels the others, and where its value is used. https://github.com/LouisCAD/Splitties/blob/017c21aaa03fc14859ea6b8e2500b3093f8dbc62/modules/coroutines/src/commonMain/kotlin/splitties/coroutines/Racing.kt#L29-52 The other code in the file supports the
function which allows to launch racers dynamically, if some coroutines need to join the race only based on some conditions.
(which justs suspends until cancelled, returning
) for UI code where multiple user actions are allowed in a scope/context.
Tim Malseed07/21/2020, 3:58 AM
The resulting flow completes as soon as one of the flows completes and cancel is called on the remaining flowI took this to mean that it does not wait for both flows to emit. Am I misinterpreting the docs?
louiscad07/21/2020, 4:01 AM
Tim Malseed07/21/2020, 4:02 AM
julian07/21/2020, 4:05 AM
waits for an emission from both flows being zipped before executing the lambda supplied to it. This lambda is the first opportunity one has to do anything with the flows. The next opportunity is downstream from the
operator. Problem is, you can't cancel either flow from inside the `zip`'s lambda. And by the time you cancel downstream of
, both flows have already emitted.
Tim Malseed07/21/2020, 4:06 AM