shutdown

Shuts down built-in dispatchers, such as Default and IO, stopping all the threads associated with them and making them reject all new tasks. Dispatcher used as a fallback for time-related operations (delay, withTimeout) and to handle rejected tasks from other dispatchers is also shut down.

This is a delicate API. It is not supposed to be called from a general application-level code and its invocation is irreversible. The invocation of shutdown affects most of the coroutines machinery and leaves the coroutines framework in an inoperable state. The shutdown method should only be invoked when there are no pending tasks or active coroutines. Otherwise, the behavior is unspecified: the call to shutdown may throw an exception without completing the shutdown, or it may finish successfully, but the remaining jobs will be in a permanent dormant state, never completing nor executing.

The main goal of the shutdown is to stop all background threads associated with the coroutines framework in order to make kotlinx.coroutines classes unloadable by Java Virtual Machine. It is only recommended to be used in containerized environments (OSGi, Gradle plugins system, IDEA plugins) at the end of the container lifecycle.