Mikael Alfredsson
02/04/2021, 1:03 PMlouiscad
02/04/2021, 1:40 PMMikael Alfredsson
02/04/2021, 1:41 PMlouiscad
02/04/2021, 1:42 PMlouiscad
02/04/2021, 1:43 PMMikael Alfredsson
02/04/2021, 1:44 PMlouiscad
02/04/2021, 1:46 PMraceOf and race + launchRacer functions.
raceOf is great for most use cases, but if you have a dynamic number of racers, or late racers, race + launchRacer is the tool you need: https://github.com/LouisCAD/Splitties/blob/1936c6c7e445c048077d8b4b7bb1c13b99e0ca0[…]coroutines/src/commonMain/kotlin/splitties/coroutines/Racing.ktlouiscad
02/04/2021, 1:48 PMraceOf and race could make it into the API of kotlinx.coroutines in the current form, or one close to it?
EDIT: If the answer is yes, I'll open an issue and a PR for that.okarm
02/04/2021, 1:48 PMrace in Android applications?Mikael Alfredsson
02/04/2021, 1:51 PMlouiscad
02/04/2021, 1:52 PMlouiscad
02/04/2021, 1:53 PMawaitAny() because its name makes it that it must not cancel the late ones, which is rarely what you want, unless you want to waste resources or have bugs.Mikael Alfredsson
02/04/2021, 1:56 PMlouiscad
02/04/2021, 1:56 PMMikael Alfredsson
02/04/2021, 1:58 PMawaitAny could take a parameter on how to handle the rest.
usecase: Send a FCM to all members of the on call support team. We are happy to know that atleast one got it, but the rest should get it if possibleMikael Alfredsson
02/04/2021, 1:59 PMMikael Alfredsson
02/04/2021, 2:00 PMlouiscad
02/04/2021, 2:00 PMawaitAny() for that push notification use case. You'd want to watch live how many are getting it out of how many, so you'd get a Flow of a ratio, and you could just use first { it.receivedCount > 1 }Mikael Alfredsson
02/04/2021, 2:01 PMlouiscad
02/04/2021, 2:01 PMlouiscad
02/04/2021, 2:02 PMawaitAny() could do it. The thing is that such an easy way to do it IMHO would lead to people often using the wrong tool, like using awaitAny() in places where they should have used raceOf or an equivalent that cancels the late ones.louiscad
02/04/2021, 2:03 PMMikael Alfredsson
02/04/2021, 2:04 PMawaitAny(CANCEL_WAITING) or awaitAny(LEAVE_WAITING) for examplelouiscad
02/04/2021, 2:04 PMMikael Alfredsson
02/04/2021, 2:05 PMlouiscad
02/04/2021, 2:05 PMlouiscad
02/04/2021, 2:05 PMlouiscad
02/04/2021, 2:08 PMawaitAny is explicit, actually, I just fear it's too easy to use it when you don't factor the late runners.
Maybe with a required parameter like this? awaitAny(cancelOthers = true)louiscad
02/04/2021, 2:08 PMMikael Alfredsson
02/04/2021, 2:09 PMcancelOthers seems reasonable.Mikael Alfredsson
02/04/2021, 2:11 PMawaitN(count = 1, cancelOthers = true) but I cant find that case now 🙂louiscad
02/04/2021, 2:12 PMMikael Alfredsson
02/04/2021, 2:14 PMMikael Alfredsson
02/04/2021, 2:15 PMraceOf code.louiscad
02/04/2021, 2:17 PM