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
670
YouTubeへのライブ配信機能をリリースするまで
yurihondo
0
2.7k
Shibuya.apk_41_DeepDiveintoRememberSaveable.pdf
yurihondo
0
450
Composeでシステムオーバーレイ / System overlay in Compose
yurihondo
0
330
Service由来のViewでViewModelを使えるようにしてみた
yurihondo
2
650
瀕死のシステムが強くなって復活する話
yurihondo
1
510
New UI Design & Debugging Tools In Android Studio
yurihondo
0
700
外部デバイスと密に連携するAndroidアプリに最適なアーキテクチャとは?
yurihondo
0
14k
Other Decks in Programming
See All in Programming
PipeCDのプラグイン化で目指すところ
warashi
1
280
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
180
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
2
14k
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
130
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
650
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.6k
VS Code Update for GitHub Copilot
74th
2
650
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
260
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
640
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
21
4k
AI駆動のマルチエージェントによる業務フロー自動化の設計と実践
h_okkah
0
170
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
410
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Code Reviewing Like a Champion
maltzj
524
40k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
820
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
690
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
4 Signs Your Business is Dying
shpigford
184
22k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
The World Runs on Bad Software
bkeepers
PRO
69
11k
BBQ
matthewcrist
89
9.7k
The Pragmatic Product Professional
lauravandoore
35
6.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
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