Ron Aharoni
12/13/2022, 8:53 AMclass KafkaConsumer {
private val scope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
fun onMessage(message: KafkaMessage<K, V>?) {
print("before launch") // this always shows
scope.launch() {
print("in coroutine") // this stops showing sometimes
process() // Async operation that might take a second or two but also with some small runBlocking inside
}
}
}
Inside of process
we make use again of the IO dispatcher to make an HTTP call.
Are there debugging tools / techniques we could use?
Would using a separate dispatcher inside process
help with isolating the problem?
ThanksSam
12/13/2022, 9:31 AMRon Aharoni
12/13/2022, 10:36 AMSam
12/13/2022, 10:40 AMprocess
has a call to runBlocking
inside? That could be an issue, especially if the code inside the runBlocking
tries to dispatch things back to the original dispatcher. I would recommend trying to make process
a suspend
function, and avoid calling runBlocking
inside code that might be running in a coroutine.streetsofboston
12/13/2022, 12:34 PMstreetsofboston
12/13/2022, 12:35 PMPablichjenkov
12/13/2022, 2:16 PMRon Aharoni
12/19/2022, 12:16 PM