
When completed, the code resumes in the main thread. In the main thread, the call is initiated and suspended, while another underlying process performs the actual networking. The following code makes a network call using Ktor.

That is asynchronous processing, but everything related to that coroutine can happen in a single thread. This allows for asynchronous, non-blocking code, without using callbacks or promises. Within a coroutine, the processing sequence may be suspended and resumed later. Get acquainted with the main concepts for using coroutines:Īsynchronous and parallel processing are different. There is also another version of routines that provides support for multiple threads. However, this version of routines cannot change threads on its own. You can suspend execution and do work on other threads while using a different mechanism for scheduling and managing that work. You cannot send work to other threads by changing a dispatcher.įor Kotlin 1.8.10, the recommended coroutines version is 1.6.4. The current version of routines, which can be used for iOS, supports usage only in a single thread. Kotlin provides the routines library with a number of high-level coroutine-enabled primitives. CoroutinesĬoroutines are light-weight threads that allow you to write asynchronous non-blocking code. Learn more about concurrency, the current approach, and future improvements. Review the pros and cons of each solution and choose the one that works best for your situation. For this, you can use the standard routines library or its multithreaded version and alternative solutions. When working with mobile platforms, you may need to write multithreaded code that runs in parallel. Check out Kotlin/Native memory management to learn about the new memory manager, which has been enabled by default since Kotlin 1.7.20.

This page describes the features of the legacy memory manager.
