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
kanmoba-returns-02.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Takuji Nishibayashi
June 12, 2019
Technology
0
280
kanmoba-returns-02.pdf
Takuji Nishibayashi
June 12, 2019
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
compose-hot-reload を試そうとした話
takuji31
0
140
CameraX使ってみた
takuji31
0
280
kotlinx.datetime 使ってみた
takuji31
0
1k
HiltのCustom Componentについて
takuji31
0
360
java.timeをAndroidで使う
takuji31
0
180
KSPを使ってコード生成
takuji31
0
440
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
3.1k
kotlinx.serialization
takuji31
0
680
AndroidXとKotlin Coroutines
takuji31
0
430
Other Decks in Technology
See All in Technology
生成AI活用でQAエンジニアにどのような仕事が生まれるか/Support Required of QA Engineers for Generative AI
goyoki
1
260
銀行の内製開発にて2つのプロダクトを1つのチームでスクラムしてみてる話
koba1210
1
140
楽しく学ぼう!ネットワーク入門
shotashiratori
1
460
バクラク最古参プロダクトで重ねた技術投資を振り返る
ypresto
0
170
プラットフォームエンジニアリングはAI時代の開発者をどう救うのか
jacopen
7
3.8k
CyberAgentの生成AI戦略 〜変わるものと変わらないもの〜
katayan
0
260
AWSの資格って役に立つの?
tk3fftk
2
360
フロントエンド刷新 4年間の軌跡
yotahada3
0
490
GCASアップデート(202601-202603)
techniczna
0
210
WebアクセシビリティをCI/CDで担保する ― axe DevTools × Playwright C#実践ガイド
tomokusaba
2
160
Go標準パッケージのI/O処理をながめる
matumoto
0
220
決済サービスを支えるElastic Cloud - Elastic Cloudの導入と推進、決済サービスのObservability
suzukij
2
660
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
160
The Cult of Friendly URLs
andyhume
79
6.8k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Mobile First: as difficult as doing things right
swwweet
225
10k
Code Reviewing Like a Champion
maltzj
528
40k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Leo the Paperboy
mayatellez
4
1.5k
Darren the Foodie - Storyboard
khoart
PRO
3
2.9k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
110
ラッコキーワード サービス紹介資料
rakko
1
2.7M
RailsConf 2023
tenderlove
30
1.4k
Transcript
5ͰΘ͔ͬͨؾʹͳΔKotlin Corou,nes @takuji31 ؼ͖ͬͯͨؔϞόΠϧΞϓϦݚڀձ #2
ࣗݾհ
ࣗݾհ • @takuji31 id:takuji31 • Takuji Nishibayashi • Hatena Co.,
Ltd. • App Team • ίϛοΫDAYS • δϟϯϓϧʔΩʔʂ • ΧΫϤϜ
ࣗݾհ • Android • Kotlin • Flu-er • ! h-ps:/
/blog.takuji31.jp • " h-ps:/ /nazuna.takuji31.jp • # $ h-ps:/ /photo.takuji31.jp
Kotlin Corou+nes
ͬͯ·͔͢ʁ
ίϧʔνϯʢӳ: co-rou(neʣͱϓϩάϥ ϛϯάͷߏͷҰछɻαϒϧʔνϯ͕Τϯτ Ϧʔ͔ΒϦλʔϯ·ͰΛҰͭͷॲཧ୯Ґͱ͢ Δͷʹର͠ɺίϧʔνϯ͍ͬͨΜॲཧΛ தஅͨ͠ޙɺଓ͖͔ΒॲཧΛ࠶։Ͱ͖Δɻ — h$ps://ja.wikipedia.org/wiki/ %E3%82%B3%E3%83%AB%E3%83%BC%E3%83%81%E3%83%B3
Corou%neʹ͍͓ͭͯ͞Β͍͠· ͠ΐ͏
suspended func*on
தஅՄೳͳؔ
suspend function fetchUser() : User { val user = //
ωοτϫʔΫ௨৴ͳͲͷॏ͍ॲཧ return user }
Corou%neContext
Corou%neͷίϯςΩετ
ෳͷElementΛΈ߹Θͤͯ࡞Δ
Job
Dispatcher
Name
Excep&onHandler
ωετՄೳ
val context = Job() + Dispatchers.Main launch(context) { // run
in main thread delay(100) val response = withContext(Dispatchers.Default) { // run in background thread networkAccess() } }
Corou%neScope
Corou%neͷείʔϓ
ContextΛ࣋ͭ
ωετՄೳ
async/launchͰ্ཱͪ͛ͨίϧʔν ϯͰྫ֎͕ى͖Δͱείʔϓશମ ͕ࢮ͵ͷͰҙ
Ϋϥογϡ͢Δͭ // ྫ֎Ͱείʔϓશମ͕ࢮΜͰΫϥογϡ͢Δ coroutineScope { try { val user =
async { fetchUser() } val series = async { fetchSeries("12345") } doSomething(user.await(), series.await()) } catch (e: IOException) { // catch͞Εͳ͍ } }
ରࡦ coroutineScope { try { // Nested scope val (user,
series) = coroutineScope { val user = async { fetchUser() } val series = async { fetchSeries("12345") } Pair(user, series) } doSomething(user.await(), series.await()) } catch (e: IOException) { // show error } }
Deferred
ϊϯϒϩοΩϯάͳFuture
val user = async { fetchUser() } // Deferred<User> val
series = async { fetchSeries("12345") } // Deferred<Series> doSomething(user.await(), series.await())
Channel
ϗοτͳετϦʔϜ
val channel = Channel<User>(Channel.CONFLATED) userObserver.addOnChangeListener { user -> launch {
channel.send(user) } } channel.consumeEach { user -> doSomething(user) }
Flow
ίʔϧυͳετϦʔϜ
Preview status
1.3.0-M1ͰExperimentalʹ
val userFlow = flow<User> { emit(observeUser()) } val seriesFlow =
flow<Series> { emit(observeSeries()) } userFlow.combineLatest(seriesFlow) { user, series -> createItemModels(user, series) }.collect { itemModels -> // show items }
Enjoy Kotlin Corou.nes life!