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
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
3リポジトリーを2ヶ月でモノレポ化した話 / How I turned 3 repositories into a monorepo in 2 months
kubode
0
220
ウォンテッドリーの「ココロオドル」モバイル開発 / Wantedly's "kokoro odoru" mobile development
kubode
2
1.3k
Firebase Dynamic Linksの代替手段を自作する / Create your own Firebase Dynamic Links alternative
kubode
0
720
技術を根付かせる / How to make technology take root
kubode
1
500
WantedlyでのKotlin Multiplatformの導入と課題 / Kotlin Multiplatform Implementation and Challenges at Wantedly
kubode
0
640
Google Play Consoleデベロッパー アカウントの確認 / Verifying your Play Console developer account
kubode
1
1.4k
Make your Android app into Multiplatform app
kubode
0
230
ウォンテッドリーにおけるモバイルアプリ開発 / iOSDC Japan 2024 Sponsor Session
kubode
1
1.5k
Jetpack ComposeのBottomSheetとの戦い / Fight with BottomSheet of Jetpack Compose
kubode
0
1.1k
Other Decks in Programming
See All in Programming
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
120
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
JavaDoc 再入門
nagise
0
320
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
560
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
490
Webフレームワークの ベンチマークについて
yusukebe
0
160
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
160
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
120
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
500
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
270
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
240
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
290
Why Our Code Smells
bkeepers
PRO
340
58k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Marketing to machines
jonoalderson
1
5.4k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
330
Visualization
eitanlees
152
17k
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.