in benchmarks/src/jmh/kotlin/benchmarks/scheduler/actors/ConcurrentStatefulActorBenchmark.kt [81:105]
fun requestorActorUnfair(
computations: List<SendChannel<Letter>>,
stopChannel: Channel<Unit>
) =
actor<Letter>(capacity = 1024) {
var received = 0
for (letter in channel) with(letter) {
when (message) {
is Start -> {
computations.shuffled()
.forEach { it.send(Letter(ThreadLocalRandom.current().nextLong(), channel)) }
}
is Long -> {
if (++received >= ROUNDS * 8) {
computations.forEach { it.close() }
stopChannel.send(Unit)
return@actor
} else {
sender.send(Letter(ThreadLocalRandom.current().nextLong(), channel))
}
}
else -> error("Cannot happen: $letter")
}
}
}