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
530
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
150
Associate Android Developer Certification
amejia481
2
280
Android development the right mindset. DroidCon Santo Domingo
amejia481
1
190
Other Decks in Programming
See All in Programming
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
170
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
140
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.7k
今から始めるClaude Code超入門
448jp
6
7.1k
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
580
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.7k
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
610
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
130
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
430
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
160
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Featured
See All Featured
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
52k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
420
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1.1k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
69
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Claude Code のすすめ
schroneko
67
210k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
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