Kotlin coroutines are using thread pools in background. How does coroutine can start executing in one thread, suspend execution, and resume on a different thread?
z
Zach Klippenstein (he/him) [MOD]
04/26/2021, 4:04 PM
Coroutines are just fancy callbacks. The
CoroutineDispatcher
is responsible for invoking the callbacks, and it can invoke them on whatever thread it wants.
Zach Klippenstein (he/him) [MOD]
04/26/2021, 4:04 PM
Like if you pass a callback to a Java API that uses `Executor`s. The
Executor
could decide to invoke the callback immediately, or schedule it to run on a different thread.