nulldev
11/03/2018, 8:37 PMclass WorkerPool {
val chanToWorkers = Channel<InputType>()
val chanFromWorkers = Channel<Pair<InputType, OutputType>>()
suspend fun doStuff(input: InputType): OutputType {
// Send input to workers to process
chanToWorkers.send(input)
// ??? What should I use to wait for the output?
}
}
I'm stuck since I need some way to suspend until the worker has processed the input. Is there any Channel.receiveIf {} function so I can do something like the below?
suspend fun doStuff(input: InputType): OutputType {
// Send input to workers to process
chanToWorkers.send(input)
return chanFromWorkers.receiveIf { it.first == input }.second
}
Am I thinking about this wrong?