Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A gentle introduction to Kotlin Coroutines
Search
Arturo Mejia
March 25, 2019
Programming
0
510
A gentle introduction to Kotlin Coroutines
Sample Code:
https://github.com/Amejia481/kotlin_coroutine_intro
Arturo Mejia
March 25, 2019
Tweet
Share
More Decks by Arturo Mejia
See All by Arturo Mejia
Hello Kotlin!
amejia481
1
140
Associate Android Developer Certification
amejia481
2
280
Android development the right mindset. DroidCon Santo Domingo
amejia481
1
180
Other Decks in Programming
See All in Programming
PHPに関数型の魂を宿す〜PHP 8.5 で実現する堅牢なコードとは〜 #phpcon_hiroshima / phpcon-hiroshima-2025
shogogg
1
180
なぜGoのジェネリクスはこの形なのか? Featherweight Goが明かす設計の核心
ryotaros
7
1.1k
Foundation Modelsを実装日本語学習アプリを作ってみた!
hypebeans
0
110
止められない医療アプリ、そっと Swift 6 へ
medley
1
170
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
480
Railsだからできる 例外業務に禍根を残さない 設定設計パターン
ei_ei_eiichi
0
480
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
220
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
230
Cloudflare AgentsとAI SDKでAIエージェントを作ってみた
briete
0
140
CSC509 Lecture 05
javiergs
PRO
0
300
Your Perfect Project Setup for Angular @BASTA! 2025 in Mainz
manfredsteyer
PRO
0
170
CI_CD「健康診断」のススメ。現場でのボトルネック特定から、健康診断を通じた組織的な改善手法
teamlab
PRO
0
210
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
431
66k
Building an army of robots
kneath
306
46k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
GraphQLとの向き合い方2022年版
quramy
49
14k
RailsConf 2023
tenderlove
30
1.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
How STYLIGHT went responsive
nonsquared
100
5.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
A designer walks into a library…
pauljervisheath
209
24k
The Invisible Side of Design
smashingmag
302
51k
Scaling GitHub
holman
463
140k
Transcript
A gentle introduction to Kotlin Coroutines Arturo Mejia Twitter: @ArturoMejia481
ArturoMejiaMarmol.com
None
Alternatives @ArturoMejia481 Threads Callbacks RX (Reactive extensions) Futures Promises
Threads @ArturoMejia481 Expensive, not easy to use. IOS deprecate threads.
DispatchQueue
Callbacks @ArturoMejia481 Don't call me, I'll call you!
Callbacks @ArturoMejia481 Callback Hell
Callbacks @ArturoMejia481 Callback Hell a.k.a Tilted Christmas Tree.
Callbacks @ArturoMejia481 Difficult error handling.
Promises and Futures @ArturoMejia481
Reactive Extensions @ArturoMejia481 You have to change the way that
you approach a problem. Operators RX Schedulers Streams
@ArturoMejia481 Reactive Extensions
@ArturoMejia481 Kotlin Coroutines Do async work the same way, exceptions,
loops, etc…
@ArturoMejia481 Kotlin Coroutines Clear differences between suspend functions
@ArturoMejia481 Kotlin Coroutines Same function signature
Coroutines = Lightweight @ArturoMejia481 Threads Coroutines
@ArturoMejia481 Kotlin Coroutines
Goal @ArturoMejia481 Suspend Dispatchers Coroutine Builders Launch Async/await
Suspend @ArturoMejia481 A key word to indicate the compiler that
a function can be suspended.
Suspend @ArturoMejia481 A suspend function should be called from a
coroutine or another suspend function.
Suspend @ArturoMejia481 The Kotlin compiler transforms the function to a
callback model and uses state machines to know when a function should be suspended or resume.
@ArturoMejia481 Coroutine ≈ Threads
Let’s get our hands dirty! @ArturoMejia481
Launch @ArturoMejia481 Launch is when we want to fire and
forget.
Async @ArturoMejia481 Async is when we want to run something,
then await the result.
Dispatchers @ArturoMejia481 DEFAULT (Computational) Uses the # cores of the
CPU, not good for computations like I/O, network, disk, etc. IO designed for doing blocking I/O operations, max #64 thread, share the pool with DEFAULT. MAIN designed to operate UI objects. Indicate in which thread pool a coroutine should run
Interoperate @ArturoMejia481 kotlinx-coroutines-rx2: Utilities for Rx. kotlinx-coroutines-jdk8: Integration with JDK8
CompletableFuture (Android API level 24). kotlinx-coroutines-android: Designed to operate UI objects.
“With a great power, comes responsibility” @ArturoMejia481 Spiderman
Questions? @ArturoMejia481
Thanks! Twitter: @ArturoMejia481 ArturoMejiaMarmol.com Android Tutorials RayWenderLich.com/u/amejia481