https://kotlinlang.org logo
Title
b

BryanT

05/21/2023, 6:25 PM
I asked in the Kafka Slack server how to handle testing a polling mechanism I have for consuming messages, that runs indefinitely. The solution offered was a CountdownLatch, which would allow me to halt the polling while testing. I’m wondering if there is a more “Kotlin-esk” way to solve this rather than the countdown latch?
a

Adam S

05/21/2023, 7:10 PM
could you share an example of the code you have at the moment? there’s some docs on async programming techniques here: https://kotlinlang.org/docs/async-programming.html#coroutines Coroutines are good for suspending work, and they’re very Kotlin-esque, but they are a big step to take if you just want a small util in your test code!
b

BryanT

05/21/2023, 7:37 PM
https://github.com/bthode/kafkagram/blob/master/telegram-response/src/main/kotlin/com/tatq/consumer/TelegramIngest.kt This is how I’m trying to use coroutineScope current. I had a finally block that I believe was being invoked when it was suspended, which I was having close my Kafka consumer.
I ripped that out, which locally seemed to fix it but once I pushed it into my cluster as container I was back to seeing my consumer being closed out from underneath me.
It’s just a toy project to try and learn Kotlin and have something to deploy into my little Microk8s cluster, so I would like to learn coroutines. I’m just not sure if how I’m using it here is on the right track.