curric

View on GitHub

./curric/kotlin/Concurrency/

Concurrency Returns

Coroutines (The Kotlin Approach)

What are Coroutines

Kotlin Docs for: Basics of Coroutines

Cancellations and Timeouts

Kotlin Docs for: Cancellations and Timeouts

Suspending Functions

Kotlin Docs for: Suspending Functions

Coroutine Context and Dispatchers

Kotlin Docs for: Coroutine Context and Dispatchers

Flow, Channels and Pipelines

Kotlin Docs for:

Exception Handling

Kotlin Docs for: Exception Handling

Shared Mutable State and Concurrency

Kotlin Docs for: Shared Mutable State and Concurrency

Threads VS Coroutines

As Kotlin is able to target the JVM and has very stable Java interop, Threads are still able to be used. Meaning now there are two different forms of Concurrency available.

Now the question becomes which do you use? Well, it depends on the situation, each have their own pros and cons. Threads are preemptively multitasked and provide concurrency and along with parallelism. Coroutines, on the ohter hand, are cooperatively multitasked and provide concurrency but do not provide parallelism. This means that coroutines have no need for support from the underlying OS. All in all, threads have their uses and so do coroutines and its important to understand which is better for which situation.