Coroutines for Kotlin Multiplatform in practise
summary
Kotlin Multiplatform coroutines work, but only if code assumes the Kotlin/Native constraints: kotlinx.coroutines ships as JVM core vs native‑mt (Ktor forces native‑mt), default dispatchers on Native can be single‑threaded and there is no common IO dispatcher, so always inject dispatchers and test the “all dispatchers on one thread” case. Freeze mutable objects or use atomicfu/AtomicRef and freeze public API early. Expose suspend as completion handlers or convert flows to Combine publishers and manually propagate errors and cancellations; async/await on Swift is still main‑thread limited.
AI-written summary · about
chapters (13)
- 0:00Introduction and speaker intro
- 1:06Coroutines in multiplatform overview
- 2:53Coroutines library choices
- 4:16Dispatchers in shared code
- 7:51Testing coroutines in common code
- 9:58Kotlin Native memory model
- 14:11Dangers of runBlocking
- 18:22Coroutines on iOS basics
- 22:34Exception handling in iOS
- 23:38Consuming Kotlin Flows in Swift
- 28:54Flows to Combine Publishers
- 36:35Async/await in Kotlin Multiplatform
- 39:48Summary and key takeaways
related talks
22mCalling Kotlin Multiplatform Coroutines from Swift with the help of KMP-NativeCoroutines
44mKotlin/Native Concurrency for Mobile Multiplatform
42mKotlin Multiplatform multithreading old and new way
31mKotlin/Native for Multiplatform Development
35mIntro to Kotlin Multiplatform
58mKotlin Multiplatform: Memory management old and new way
28mConcurrency for Imposters
39mKotlin Native Concurrency Explained
