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
The Pitfalls of Cancellation
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Masatoshi Kubode
December 22, 2020
Programming
1.9k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Pitfalls of Cancellation
Masatoshi Kubode
December 22, 2020
More Decks by Masatoshi Kubode
See All by Masatoshi Kubode
AIチャットの改善から見えた、良いAI体験とは / What Constitutes a Good AI Experience: Insights from Improving AI Chat
kubode
0
150
3リポジトリーを2ヶ月でモノレポ化した話 / How I turned 3 repositories into a monorepo in 2 months
kubode
0
240
ウォンテッドリーの「ココロオドル」モバイル開発 / Wantedly's "kokoro odoru" mobile development
kubode
2
1.3k
Firebase Dynamic Linksの代替手段を自作する / Create your own Firebase Dynamic Links alternative
kubode
0
730
技術を根付かせる / How to make technology take root
kubode
1
500
WantedlyでのKotlin Multiplatformの導入と課題 / Kotlin Multiplatform Implementation and Challenges at Wantedly
kubode
0
650
Google Play Consoleデベロッパー アカウントの確認 / Verifying your Play Console developer account
kubode
1
1.4k
Make your Android app into Multiplatform app
kubode
0
240
ウォンテッドリーにおけるモバイルアプリ開発 / iOSDC Japan 2024 Sponsor Session
kubode
1
1.5k
Other Decks in Programming
See All in Programming
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
210
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
240
Contextとはなにか
chiroruxx
1
390
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.9k
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
140
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
0
430
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
250
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
120
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
120
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
250
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
350
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
190
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
Amusing Abliteration
ianozsvald
1
220
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Ethics towards AI in product and experience design
skipperchong
2
320
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to Talk to Developers About Accessibility
jct
2
290
A Modern Web Designer's Workflow
chriscoyier
698
190k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Transcript
©2020 Wantedly, Inc. The Pitfalls of Cancellation Presentation Subtitle 2020/12/22
Masatoshi Kubode https://unsplash.com/photos/J8sh37XZ8ww
©2020 Wantedly, Inc. ٱอग़խढ़ 8BOUFEMZ 8BOUFEMZ7JTJUͷ"OESPJEΞϓϦΛ։ൃ͍ͯ͠·͢ɻ ,PUMJO .BHJDUIF(BUIFSJOH UIJTUP4USJOH 5XJUUFS
!TXJ[@BSE (JU)VC !LVCPEF
ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2020 Wantedly, Inc. $PSPVUJOFTͰى͖ͨΫϥογϡͷ
©2020 Wantedly, Inc. ͋ΔͷΫϥογϡϨϙʔτ
ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2020 Wantedly, Inc.
©2020 Wantedly, Inc. ֘ίʔυ class FetchDiscoverPostsUseCaseImpl( private val discoverRepository: DiscoverRepository,
) : FetchDiscoverPostsUseCase { override suspend operator fun invoke(sectionId: DiscoverSectionId) { try { return discoverRepository.fetchDiscoverPosts(sectionId) } catch (@Suppress("TooGenericExceptionCaught") e: Throwable) { throw FetchDiscoverProjectsUseCase.Error( "Failed to fetch discover posts for section: $sectionId”, e ) } } } ←ίϐϖͰTypoͯ͠Δ Repositoryͷྫ֎Λϥοϓͯ͠ Rethrowͯ͠Δ͚ͩͳͷʹ ͳͥ?
ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2020 Wantedly, Inc. 4UBDL5SBDFΛΑ͘ݟΔ
©2020 Wantedly, Inc. ͋ΔͷΫϥογϡϨϙʔτ JobCancellationException͕ݪҼ
ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2020 Wantedly, Inc. +PC$BODFMMBUJPO&YDFQUJPOͱ
©2020 Wantedly, Inc. JobCancellationException https://atoulme.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-job-cancellation-exception/index.html Job.cancel()͞Εͨͱ͖ʹ suspend͍ͯ͠Δ͔ؔΒThrow͞ΕΔ CoroutinesͷγεςϜతͳྫ֎
©2020 Wantedly, Inc. ֘ίʔυ class FetchDiscoverPostsUseCaseImpl( private val discoverRepository: DiscoverRepository,
) : FetchDiscoverPostsUseCase { override suspend operator fun invoke(sectionId: DiscoverSectionId) { try { return discoverRepository.fetchDiscoverPosts(sectionId) } catch (@Suppress("TooGenericExceptionCaught") e: Throwable) { throw FetchDiscoverProjectsUseCase.Error( "Failed to fetch discover posts for section: $sectionId”, e ) } } } ͭ·ΓɺCoroutinesͷγεςϜతͳྫ֎Λ ϥοϓͯ͠͠·͔ͬͨΒΫϥογϡͨ͠
©2020 Wantedly, Inc. JobCancellationExceptionৄղ ͱͱJavaͷฒྻॲཧAPIͰΘΕ͍ͯͨྫ֎
©2020 Wantedly, Inc. Javaͷੈք java.util.concurrent.Future#get() try { future.get(); } catch
(ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } CancellationExceptionRuntimeException ͳͷͰ໌ࣔతͳcatchෆཁ CancellationΛcatchͪ͠Ό͏͜ͱ͕ى͖ͮΒ͍
©2020 Wantedly, Inc. Kotlinͷੈք Kotlinʹݕࠪྫ֎͕ͳ͍ catch(Throwable)͕ͪ͠ CoroutinesͰࠓճͷΑ͏ͳʹܨ͕Γ͍͢ cancel()ͯ͠ͳ͍͔ͱ͍͏ςετ;ͭ͏ॻ͔ͳ͍͠ɺ ݱঢ়ϓϩάϥϚ͕ؾΛ͚ͭΔ͔͠ͳ͍ʁ
©2020 Wantedly, Inc. Ͳ͏͖͔͢ launch { try { codeThatCanThrowExceptions() //
// } catch (e: Throwable) { // } catch (e: Exception) { // } catch (e: RuntimeException) { // } catch (e: IllegalStateException) { // } catch (e: CancellationException) { } catch (e: SpecificException) { // throw MyException(e) } } // OR launch { try { codeThatCanThrowExceptions() } catch (e: Throwable) { throw e as? CancellationException ?: MyException(e) } }
©2020 Wantedly, Inc. w ,PUMJOʹݕࠪྫ֎͕ͳ͍ͷͰࡶʹ͕͕ͪͩ͠ɺ $PSPVUJOFTͰ5PP(FOFSJDͳDBUDIةݥ w DBUDI͔ͨͬͨ͠Β$BODFMMBUJPOSFUISPX w ͘͠$PSPVUJOF&YDFQUJPO)BOEMFSΛ͏
w -JOUແࢹ͠ͳ͍ ·ͱΊ
ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2020 Wantedly, Inc.