reactormonk
10/25/2024, 10:54 AMsuspend fun <R> race(vararg races: suspend () -> R): R {
return channelFlow {
for (race in races) {
launch { send(race()) }
}
}.first()
}
for my little interpreter:
@Serializable
sealed interface Logic: Command {
@Serializable
@SerialName("Race")
// race any number of commands, will return as soon as the first one happens.
data class Race(val commands: List<Command>): Logic
}
But the run
doesn't really make the types align:
is Command.Logic.Race -> {
race(commands.map { command -> command.run() }.toTypedArray())
}
Dmitry Khalanskiy [JB]
10/25/2024, 11:00 AMrace
accepts functions, but you're passing it an array of values. Please try { command -> { command.run() } }
instead of { command -> command.run() }
.reactormonk
10/25/2024, 11:01 AMDmitry Khalanskiy [JB]
10/25/2024, 11:02 AM{ command -> suspend { command.run() } }
?reactormonk
10/25/2024, 11:04 AM*
for the varargsJilles Soeters
10/28/2024, 4:27 PMselect
for this?Dmitry Khalanskiy [JB]
10/28/2024, 4:30 PM