Hi,
I have a
taskChannel
, a
resultChannel
, a producer and multiple consumers. The producer is lightning fast and the consumers need a bit of time. Once the producer is done, it closes the taskChannel.
launch {
tasks.forEach {
taskChannel.send(it)
}
taskChannel.close()
}
Then this is the consumer side of things.
launch {
repeat (10) {
launch {
for (task in taskChannel) {
val result = process(task)
resultChannel.send(result)
}
}
}
}
This resultChannel undergoes one final step, which is logging the results:
for (result in resultChannel) {
log(result)
}
resultChannel.close()
My question is really just if I’ve closed the channels at the correct times etc. Also, is this a correct usage of the channels, or have I created some antipatterns or some such here? Any replies appreciated. It’s my first time looking into channels, and I like the way they let me start all three processes (production, consumption and logging) at the same time