SuspendApp
fun SuspendApp(context: CoroutineContext = Dispatchers.Default, uncaught: (Throwable) -> Unit = Throwable::printStackTrace, timeout: Duration = Duration.INFINITE, block: suspend CoroutineScope.() -> Unit)
An unsafe blocking edge that wires the CoroutineScope (and structured concurrency) to the SuspendApp, such that the CoroutineScope gets cancelled when the App
is requested to gracefully shutdown. =>SIGTERM
&SIGINT
on Native & NodeJS and a ShutdownHook for JVM.
It applies backpressure to the process such that they can gracefully shutdown.
Parameters
context
the CoroutineContext where block will execute. Use EmptyCoroutineContext to create an CoroutineDispatcher
for the main thread and run there instead.
timeout
the maximum backpressure time that can be applied to the process. This emulates a SIGKILL
command, and after the timeout is passed the App will forcefully shut down regardless of finalizers.
block
the lambda of the actual application.