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
Kotlin Coroutines
Search
Rygel Louv
November 14, 2020
Programming
0
44
Kotlin Coroutines
Introduction to Kotlin Coroutines. We went through the basic concepts of Coroutines.
Rygel Louv
November 14, 2020
Tweet
Share
More Decks by Rygel Louv
See All by Rygel Louv
Exploring Mobile Release Management: Strategies and Best Practices
rygelouv
0
100
State Machines and How they Shape Mobile Architectures
rygelouv
0
91
Feature Flags for Mobile Development
rygelouv
0
160
Build and Publish an Open Source Android Library for Fun and Non profit
rygelouv
1
64
Kotlin "by" Delegation
rygelouv
0
62
Introduction to Type-Safe Builders: create a DSL in Kotlin
rygelouv
0
200
Annotation processing: generate code, eliminate boilerplate
rygelouv
0
110
Other Decks in Programming
See All in Programming
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
190
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
800
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
630
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
900
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
320
useSyncExternalStoreを使いまくる
ssssota
6
1.3k
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
170
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
280
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
350
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
130
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
300
Featured
See All Featured
Visualization
eitanlees
146
15k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
A Philosophy of Restraint
colly
203
16k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Fireside Chat
paigeccino
34
3.1k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Code Reviewing Like a Champion
maltzj
521
39k
Designing for humans not robots
tammielis
250
25k
The Invisible Side of Design
smashingmag
298
50k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Transcript
Kotlin Coroutines Rygel Louv Dakar Ruby Brigade.
2019 Rygel Louv Software engineer
- Simplifying asynchronous programming - Write async code that looks
like sync code Coroutines: what problem do they solve ? P . 3
Synchronous blocking code P . 3
Synchronous blocking code P . 3
Async code using a callback P . 3
Callback Hell P . 3
Coroutines are the best of both worlds P . 3
Coroutines create a callback under the hood called Continuation P
. 3 Callback
State Machine and Continuation Passing Style P . 3
What is a coroutine ? P . 3 - Not
a thread - Takes a piece of code and run it in a thread - Lightweight thread
- Context switching: withContext - Dispatchers Coroutines concepts P .
3
- Dispatcher.Main: Main thread - Dispatcher.IO: Network and disk -
Dispatcher.Default: CPU (heavy computation) Coroutines dispatchers P . 3
- Canceling coroutine execution - Following a Lifecycle - Informing
components when Exception happens Coroutines concepts: Structured concurrency P . 3 Avoid memory leaks
- Keep track of coroutines - Ability to cancel them
- Is notified of failures Structure concurrency: Scopes P . 3
Coroutine scope: launching coroutines P . 3
P . 3 Coroutine scope: launching coroutines
P . 3 Coroutine scope: launching coroutines Parent Child Scope
will get all exceptions thrown by this function
- Cancels all coroutines - Can not start more coroutines
Scopes: cancelation P . 3
Suspend function in a coroutine P . 3
- When a child fails, the scope get notified -
Then the scope cancel itself and cancel all children Scopes exception handling: Job P . 3
- The failure of one child does not affect other
children - When the scope get notified of a failure, nothing happens Scopes exception handling: SupervisorJob P . 3
Creating coroutines P . 3
Creating coroutines: Launch P . 3 - Creates a new
coroutine - Fire and forget
Creating coroutines: Async P . 3 - Creates a new
coroutine - Returns a value Deferred == Promise/Future
P . 3
Cancellation requires co-operation P . 3
Cancellation require co-operation P . 3 - Check if coroutine
is Active
Next on coroutines P . 3 - Dive deeper in
Continuation Passing Style - More on co-operation - Channels - Flows
P . 27 THANK YOU