The Internals of Concurrency in Kotlin

It's important that you have an idea of how suspending computations actually work. In this chapter, we will analyze how compiler transforms suspending functions into state machines, how the thread switching happens, and how exceptions are propagated. Some things that will be covered in this chapter are listed here:

  • Continuation Passing Style (CPS) and how it's related to suspending computations
  • Many different internal classes that are used when the coroutines are compiled into bytecode
  • The Flow of interception of a coroutine, including how threads are switched
  • Exception propagation with and without a CoroutineExceptionHandler

During the early sections of this chapter, we will be transforming a suspending function, imitating the work that the compiler does. Please notice that the code we write will not match the bytecode generated by the compiler exactly, but will be accurate enough to allow you to understand what is really happening.

This chapter doesn't include code examples for you to run in the IDE. The first half of the chapter uses pseudo Kotlin to represent what the compiler does, and the second half explains some of Kotlin's internal code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.200.3