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
490
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
270
Android development the right mindset. DroidCon Santo Domingo
amejia481
1
180
Other Decks in Programming
See All in Programming
Python型ヒント完全ガイド 初心者でも分かる、現代的で実践的な使い方
mickey_kubo
1
110
A2A プロトコルを試してみる
azukiazusa1
2
1.4k
“いい感じ“な定量評価を求めて - Four Keysとアウトカムの間の探求 -
nealle
1
10k
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
770
ニーリーにおけるプロダクトエンジニア
nealle
0
830
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
11k
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
1
18k
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
120
AI駆動のマルチエージェントによる業務フロー自動化の設計と実践
h_okkah
0
150
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
570
VS Code Update for GitHub Copilot
74th
2
640
Featured
See All Featured
Designing Experiences People Love
moore
142
24k
Site-Speed That Sticks
csswizardry
10
690
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.9k
Automating Front-end Workflow
addyosmani
1370
200k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
A better future with KSS
kneath
238
17k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
Agile that works and the tools we love
rasmusluckow
329
21k
RailsConf 2023
tenderlove
30
1.1k
The Language of Interfaces
destraynor
158
25k
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