koufa
08/13/2024, 11:36 AMprivate val coroutineScope = CoroutineScope(SupervisorJob() + <http://Dispatchers.IO|Dispatchers.IO>)
private val channel = Channel<Int>(1)
@POST
@Path("/channel")
suspend fun sendToChannel() {
coroutineScope.launch {
delay(Random.nextLong(1000, 10000))
println("Send to Channel Start")
channel.send(100)
println("Send to Channel Finish")
println("/channel finish")
}
}
fun onStart(@Observes startupEvent: StartupEvent) {
coroutineScope.launch {
channel.consumeEach {
println("Consume each: $it")
}
}
}
Sam
08/13/2024, 2:07 PMsendToChannel
function shouldn't be suspend
if all it's doing is launching a separate coroutine.
• What do you mean by "conflate"? At the moment, your channel will deliver every item. You can change that by changing its capacity, e.g. to Channel.CONFLATED
.koufa
08/13/2024, 2:59 PMsuspend
was only used for Quarkus to continue the request in vert.x-eventloop-thread
and not unnecessarily switch to a worker thread. This avoids the thread switching even if the suspend
is not used directly
• I meant if consumptions happens sequentially for every event in the correct order. But yes that should be the case I tested it with the sample code and it should work