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
Between Love and Hate: Coroutines
Search
Maryna Shaposhnikova
July 19, 2018
Programming
110
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Between Love and Hate: Coroutines
Maryna Shaposhnikova
July 19, 2018
More Decks by Maryna Shaposhnikova
See All by Maryna Shaposhnikova
Mobile Platform Team. Grab.
marinameier
0
370
Other Decks in Programming
See All in Programming
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
Next.js: The final boss of Web Performance
guaca
0
250
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
270
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
すこし踏み込む CancellationToken
htkym
2
1.7k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
AWSに止められる覚悟してますか?
morizo_1984
2
530
残高管理から台帳サービスへの進化
artoy
1
200
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
880
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
Featured
See All Featured
Claude Code のすすめ
schroneko
67
230k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
It's Worth the Effort
3n
188
29k
ラッコキーワード サービス紹介資料
rakko
1
5.3M
Designing Powerful Visuals for Engaging Learning
tmiket
1
610
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Ethics towards AI in product and experience design
skipperchong
2
430
Transcript
Between Love and Hate: Coroutines Maryna Shaposhnikova Android dev Glindev
Languages:
There are two types of Coroutines Stackfull Stackless
None
Why we need it? asynchronous, non-blocking code light-weight threads
What does it means light-weight threads? - don’t have an
own stack - don’t map on native thread - don’t require context switching on processor conclusion : they are lighter than threads
How it works? Callback?!?
State machine - if-conditions - switch structures.
None
Continuation is a state of the suspended coroutine at suspension
point CoroutineContext like a collection of thread-local variables, but… persistent
start get my wizzard add to list get a user
get a wizard suspend suspend wizard :) suspend
- Do background task - Switch to UI - Show
user launch (UI) || launch(CommonPool)
UI { background { load() //suspend function } show() }
Suspend functions are only allowed to be called from a coroutine or another suspend function.
launch {} async {} Job Deferred aka promise join() await()
w/o result with result
Compare
launch (UI) { launch (CommonPool) {}.join() launch (CommonPool) {}.join() launch
(CommonPool) {}.join() } launch (UI) { async (CommonPool) {}.await() async (CommonPool) {}.await() async (CommonPool) {}.await() }
withContext() ONE or MANY?
launch (UI) { launch (CommonPool) { getRandomUser() getRandomUser() getRandomUser() }.join()
} launch (UI) { withContext (CommonPool) { getRandomUser() getRandomUser() getRandomUser() } }
= 3000 ms 1000 ms 1000 ms 1000 ms
= 1000 ms
launch (UI) { val def1 = async (CommonPool) {} val
def2 = async (CommonPool) {} val def3 = async (CommonPool) {} def1.await() def2.await() def3.await() } joinAll(job1, job2, job3) awaitAll(job1, job2, job3) launch (UI) { val job1 = launch (CommonPool) {} val job2 = launch (CommonPool) {} val job3 = launch (CommonPool) {} job1.join() job2.join() job3.join() }
None
Exception
suspendCoroutine callback { callback { callback { callback { print(‘I
hate callback hell”) } } } }
None
Retrofit?
None
- Build abstraction - Use Channels for modularization - Avoid
to use CommonPool - Avoid to use UI
Could coroutines replace Rx?
None
Thank you! Maryna Shaposhnikova Android dev Glindev Sample project https://github.com/MarinaShaposhnikova/M
agicCoroutines