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.2k
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 Uncovered
yurihondo
0
160
Road to Single Activity
yurihondo
2
660
YouTubeへのライブ配信機能をリリースするまで
yurihondo
0
2.7k
Shibuya.apk_41_DeepDiveintoRememberSaveable.pdf
yurihondo
0
440
Composeでシステムオーバーレイ / System overlay in Compose
yurihondo
0
330
Service由来のViewでViewModelを使えるようにしてみた
yurihondo
2
650
瀕死のシステムが強くなって復活する話
yurihondo
1
500
New UI Design & Debugging Tools In Android Studio
yurihondo
0
700
外部デバイスと密に連携するAndroidアプリに最適なアーキテクチャとは?
yurihondo
0
14k
Other Decks in Programming
See All in Programming
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
300
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
500
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
240
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
20
3.7k
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
110
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
560
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
230
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
270
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
130
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
660
A2A プロトコルを試してみる
azukiazusa1
2
1.2k
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Agile that works and the tools we love
rasmusluckow
329
21k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
A designer walks into a library…
pauljervisheath
207
24k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
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