Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
A gentle introduction to Kotlin Coroutines
Search
Arturo Mejia
March 25, 2019
Programming
550
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
A gentle introduction to Kotlin Coroutines
Sample Code:
https://github.com/Amejia481/kotlin_coroutine_intro
Arturo Mejia
March 25, 2019
More Decks by Arturo Mejia
See All by Arturo Mejia
Hello Kotlin!
amejia481
1
160
Associate Android Developer Certification
amejia481
2
310
Android development the right mindset. DroidCon Santo Domingo
amejia481
1
220
Other Decks in Programming
See All in Programming
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
2.9k
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
280
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
270
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
560
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
280
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
220
SREの越境 / SRE Collaboration
y0hgi
2
290
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
140
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
130
JRuby: Past, Present, and Future
headius
0
210
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
250
Featured
See All Featured
KATA
mclloyd
PRO
35
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
910
Why Our Code Smells
bkeepers
PRO
340
58k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
590
Test your architecture with Archunit
thirion
2
2.4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
GraphQLとの向き合い方2022年版
quramy
50
15k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
510
How to train your dragon (web standard)
notwaldorf
97
6.8k
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