Jan
04/12/2025, 10:34 AMApplicationStopPreparing
listener gets called twice. (1) When the server was stopped and the coroutine resumed and (2) When the compose application closes and I get a Already resumed, but proposed with update kotlin.Unit
exception
suspendCancellableCoroutine {
server.monitor.subscribe(ApplicationStopPreparing) { _ ->
it.resume(Unit)
timeoutScope.cancel()
}
server.start()
it.invokeOnCancellation { _ ->
server.stop()
timeoutScope.cancel()
}
}
Any idea why this listener gets called on application exit? The server should be down, no?simon.vergauwen
04/12/2025, 11:22 AMAlready resumed, but proposed with update kotlin.Unit
.
What is your use-case? If you're playing with shutdown and coroutines perhaps this might interest you. https://github.com/arrow-kt/suspendapp?tab=readme-ov-file#suspendapp-with-ktorJan
04/12/2025, 11:29 AMsimon.vergauwen
04/12/2025, 11:43 AMserver.stop
but that in turn calls subscribe(ApplicationStopPreparing)
and then you resume
after invokeOnCancellation
got called. Which is a violation of the contract, and hence you see that exception.
You can probably safely ignore that exception though, or introduce a val isCancelled = AtomicBoolean(false)
to avoid that scenario, and see if it still occurs.Jan
04/12/2025, 11:50 AM