``` val queueListener = launch { while ...
# coroutines
a
Copy code
val queueListener = launch {
        while (isActive) {
            // do something
        }
    }

    Runtime.getRuntime().addShutdownHook(Thread {
        <http://logger.info|logger.info> { "Cancellation requested" }
        queueListener.cancel()
    })

    queueListener.join()
    <http://logger.info|logger.info> { "Exiting program" }
why would “Exiting program” never show up? are there any other way to do it? I am also considering channel that sends some cancellation event. But what wold be the better way to handle this?
s
What happens if you add a
yield()
statement inside your
while(isActive)
loop…
a
it doesn’t change anything
s
Try this for debugging: First: Does your program end or does it hang? If it ends, try this: Instead of a shutdown-hook, use a timer to cancel queueListener. If that works, maybe the 'join' call doesn't work when the program is shut down.
a
I fixed the issue by waiting in thread created by webhook until queueListener reports successful cleanup