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
470
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
130
Associate Android Developer Certification
amejia481
2
270
Android development the right mindset. DroidCon Santo Domingo
amejia481
1
170
Other Decks in Programming
See All in Programming
アーキテクトと美学 / Architecture and Aesthetics
nrslib
12
3.3k
AWSで雰囲気でつくる! VRChatの写真変換ピタゴラスイッチ
anatofuz
0
130
複数ドメインに散らばってしまった画像…! 運用中のPHPアプリに後からCDNを導入する…!
suguruooki
0
460
AWS で実現する安全な AI エージェントの作り方 〜 Bedrock Engineer の実装例を添えて 〜 / how-to-build-secure-ai-agents
gawa
8
580
Windows版PHPのビルド手順とPHP 8.4における変更点
matsuo_atsushi
0
400
エンジニア未経験が最短で戦力になるためのTips
gokana
0
260
DataStoreをテストする
mkeeda
0
270
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
690
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
110
国漢文混用体からHolloまで
minhee
1
140
生成AIを使ったQAアプリケーションの作成 - ハンズオン補足資料
oracle4engineer
PRO
3
120
php-fpm がリクエスト処理する仕組みを追う / Tracing-How-php-fpm-Handles-Requests
shin1x1
5
2k
Featured
See All Featured
KATA
mclloyd
29
14k
Speed Design
sergeychernyshev
28
870
Visualization
eitanlees
146
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
The Invisible Side of Design
smashingmag
299
50k
Side Projects
sachag
452
42k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Building a Modern Day E-commerce SEO Strategy
aleyda
39
7.2k
A designer walks into a library…
pauljervisheath
205
24k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.5k
The Pragmatic Product Professional
lauravandoore
33
6.5k
Docker and Python
trallard
44
3.3k
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