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
Behavior of nested async in Kotlin Coroutines
Search
yurihondo
December 18, 2018
Programming
2
1.1k
Behavior of nested async in Kotlin Coroutines
yurihondo
December 18, 2018
Tweet
Share
More Decks by yurihondo
See All by yurihondo
Road to Single Activity
yurihondo
1
240
YouTubeへのライブ配信機能をリリースするまで
yurihondo
0
2.2k
Shibuya.apk_41_DeepDiveintoRememberSaveable.pdf
yurihondo
0
400
Composeでシステムオーバーレイ / System overlay in Compose
yurihondo
0
250
Service由来のViewでViewModelを使えるようにしてみた
yurihondo
2
540
瀕死のシステムが強くなって復活する話
yurihondo
1
490
New UI Design & Debugging Tools In Android Studio
yurihondo
0
670
外部デバイスと密に連携するAndroidアプリに最適なアーキテクチャとは?
yurihondo
0
14k
Other Decks in Programming
See All in Programming
A New Era of Testing
mannodermaus
2
510
GenU導入でCDKに初挑戦し、悪戦苦闘した話
hideg
0
160
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
4
90k
Rechartsで楽にゴリゴリにカスタマイズする!
10tera
1
170
Go1.23で入った errorsパッケージの小さなアプデ
kuro_kurorrr
2
390
Jakarta EE meets AI
ivargrimstad
1
500
How to Break into Reading Open Source
kaspth
2
210
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
430
Understand the mechanism! Let's do screenshots tests of Compose Previews with various variations / 仕組みから理解する!Composeプレビューを様々なバリエーションでスクリーンショットテストしよう
sumio
3
790
2024 컴포즈 정원사
jisungbin
0
150
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
2
120
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
270
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
93
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
5
480
Building an army of robots
kneath
302
42k
WebSockets: Embracing the real-time Web
robhawkes
59
7.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
359
19k
What the flash - Photography Introduction
edds
67
11k
Rebuilding a faster, lazier Slack
samanthasiow
78
8.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
326
21k
In The Pink: A Labor of Love
frogandcode
139
22k
A Philosophy of Restraint
colly
202
16k
Atom: Resistance is Futile
akmur
261
25k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
Transcript
Behavior of nested async in Kotlin Coroutines
About me Androidアプリ開発@DeNA 趣味は、ストリートダンス 今年、長男が爆誕 2 URI 本戸 裕理 (ホンド
ユウリ)
Introduction 今更ですが! Kotlin 1.3より、Coroutineの安定版が 利用できるようになりました 3
Introduction 私が携わるプロジェクトでもCoroutineの アップデートが 行われました 4
Introduction 結果、 アップデート起因のバグを埋め込み、 修正をする事になりました 5
Introduction そう、 あるあるです 6
Introduction (流出はしていません) 一応、最近センシティブだからね 7
Introduction 今日は、バグ対応から学んだ ◦ ネストしたasyncの振舞いと対応方法 について簡単にお話させて頂きます 8
ネストしたasyncの振舞いと対応方法 9
ver. 0.30.0より、ネストしたasyncのキャンセルが、 親のcoroutineにも伝播するようになったため、 今までエラーハンドリングを意識していなかった 箇所で例外が発生した 該当のFeature <https://github.com/Kotlin/kotlinx.coroutines/releases/tag/0.30.0> Overview for Bug
10
例えば、 以下のようなケースで例外が発生するようになった Example 11
例外が親のlaunchにも伝播する Example 12 Exception
Solution 1 withContextを利用 13
Solution 2 スコープを切り替える 14
今回の例であれば、launchにCoroutineExceptionHandler を渡して ネストされたのCoroutineのエラーをまとめてしまう Solution 3 例外の集約 15
※以下は、supervisorScopeの例 Solution 4 Supervisionを導入 16
まとめ 17 これからネスト状態でasyncを扱うときは... 1. withContextを使う 2. Suspend関数に切り出す 3. 例外の集約 4.
Supervisionの導入 辺りを検討できると良いかも...そして...
まとめ 18 Release Note は、しっかり読みましょう!!! (自戒)
Reference 今回の発表の不明点は、以下でほぼ解消されます 19 ◦ Kotlin Coroutines 0.30.2のExceptionが伝わる仕組み <https://qiita.com/takahirom/items/2846caa1d51e868ef88b> ◦ Kotlin
Coroutine 1.0.0までに夏から変わったところ <http://sys1yagi.hatenablog.com/entry/2018/12/08/181232>
THANKS! You can find me at: Twitter : URI -
@yuyuyuyuyuri Pokemon GO : 05URI28 - 0188 7196 1789 20