Kotlin Coroutines
summary
Kotlin 1.1 implements async/await as library functions backed by coroutines so asynchronous work looks sequential; async returns a Deferred (promise/future) with await which suspends the coroutine without blocking threads. Coroutines are lightweight, compile with a hidden compiler adds Continuation parameter and become a state machine so only one object represents suspension points; builders include async, launch and runBlocking, cancellation is cooperative, exceptions propagate via try/catch, contexts let you resume on UI or thread pools, and the library (channels, actors) is currently experimental.
AI-written summary · about
chapters (21)
- 0:00Intro
- 0:26Kotlin Coroutines
- 3:10Solution 1: callbacks
- 5:52Coroutine is similar to a thread
- 10:58Example: waiting for two asynchronous computations to complete
- 12:09Stepping back: what's wrong with blocking thread?
- 15:37async starts new computation
- 16:24await is a suspend function
- 16:56await suspends computation
- 21:58Custom executor async (CustomContext)
- 24:56Computation on Ul thread
- 26:37Check cancellation explicitly in computation code
- 27:03Library suspend functions like await, delay check for cancellation
- 27:15You can run the code without cancellation
- 27:29Programming with suspend functions
- 29:00Example: simple consecutive logic
- 31:29Rewrite with suspend functions
- 33:50Coroutine Builders start a coroutine
- 35:30Nested coroutines
- 37:05Implementation details
- 46:22Experimental status of Coroutines
related talks
59mKotlin coroutines: new ways to do asynchronous programming
42mKotlin Coroutines: Beyond async/await
47mKotlin Coroutines
30mBetter asynchronous programming with Kotlin Coroutines
01h 03mUsing Kotlin Coroutines for Asynchronous and Concurrent Programming
46mIntroduction to Coroutines
11mKotlin Coroutines: Design and Implementation
57mAsynchronous but Clear: Coroutines in Kotlin
