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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
160
3リポジトリーを2ヶ月でモノレポ化した話 / How I turned 3 repositories into a monorepo in 2 months
kubode
0
250
ウォンテッドリーの「ココロオドル」モバイル開発 / Wantedly's "kokoro odoru" mobile development
kubode
2
1.4k
Firebase Dynamic Linksの代替手段を自作する / Create your own Firebase Dynamic Links alternative
kubode
0
740
技術を根付かせる / 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
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
460
Google Apps Script で Ruby を動かす
kawahara
0
120
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
200
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
450
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
180
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
1.1k
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.7k
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
360
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
180
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1.1k
FDEが実現するAI駆動経営の現在地
gonta
2
250
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
190
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
240
AI: The stuff that nobody shows you
jnunemaker
PRO
9
860
Done Done
chrislema
186
16k
Site-Speed That Sticks
csswizardry
13
1.4k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
230
New Earth Scene 8
popppiees
3
2.4k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
BBQ
matthewcrist
89
10k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Building an army of robots
kneath
306
46k
Six Lessons from altMBA
skipperchong
29
4.4k
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.