Are there any examples/patterns for graceful shutd...
# coroutines
p
Are there any examples/patterns for graceful shutdown with coroutines?
g
something like combination of withTimeout and someJob.cancelAndJoin()?
Job.cancel already kinda graceful shutdown, it’s up to coroutine follow or not cancellation, because any suspend call can be wrapped with NonCancellable context
p
Thee context of this question is I have started implementing a TCP server using coroutines. I have a supervisorScope wrapping the main receive loop that launches child jobs for each connection. I would like to handle using a Runtime shutdown hook (or some other way of handling SIGINT) such that each client connection is closed and any pending work is finished (such as draining buffers on to downstream services). I’ve tried cancelling the supervisor scope on shutdown, but it doesn’t run the code following it to close things down, even if wrapped in NonCancellable
g
Hard to say without some example, noncancellable definitely works, or launching coroutine on another scope. Or even final + blocking code, depends on case