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
Takuji Nishibayashi
June 12, 2019
Technology
0
120
kanmoba-returns-02.pdf
Takuji Nishibayashi
June 12, 2019
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
KSPを使ってコード生成
takuji31
0
160
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
690
kotlinx.serialization
takuji31
0
440
AndroidXとKotlin Coroutines
takuji31
0
260
AndroidXに潜む便利なヤツら
takuji31
0
110
Kotlin Inline Class
takuji31
0
95
No more Adapter with Epoxy and Data Binding
takuji31
0
780
クロスプラットフォーム開発3種の神器 React Native / TypeScript / GraphQL
takuji31
7
6k
KanmobaInKanto
takuji31
1
82
Other Decks in Technology
See All in Technology
Delivering Millions of Messages within seconds @ Duolingo
pelelgrino
0
320
WebアプリケーションにおけるPDOの使い方入門 / phpcon odawara 2024
meihei3
2
420
アプリがつくるNOT A HOTELブランド
hokuts
0
450
DevOpsDays History and my DevOps story
kawaguti
PRO
8
1.5k
HEXA OSINT CTF V3 作戦会議
meow_noisy
0
110
**強い**エンジニアのなり方 - フィードバックサイクルを勝ち取る / grow one day each day
soudai
60
17k
Aurora MySQL v3(MySQL8.0互換)の オンラインDDLの罠挙動を全バージョンで検証した
yutakikai
0
150
4年前、あるじゃん老害エンジニアLT合戦に登壇、米国西海岸コンピュータ歴史博物館体験記の続編
toshi_atsumi
0
190
ユーザーストーリーのレビューを自動化したみたの
bun913
1
300
キャラクター制御のためのプロンプト術 for LINE Bot
uezo
0
520
0→1開発における技術選定において一番大切なこと
bicstone
1
320
ここが嬉しいABAC ここが辛いよABAC #再解説+補足編
masahirokawahara
0
200
Featured
See All Featured
A better future with KSS
kneath
230
16k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
Visualization
eitanlees
135
14k
The MySQL Ecosystem @ GitHub 2015
samlambert
242
12k
It's Worth the Effort
3n
180
27k
Imperfection Machines: The Place of Print at Facebook
scottboms
258
12k
Side Projects
sachag
451
41k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
1
1.3k
Agile that works and the tools we love
rasmusluckow
323
20k
10 Git Anti Patterns You Should be Aware of
lemiorhan
645
57k
Art, The Web, and Tiny UX
lynnandtonic
288
19k
Ruby is Unlike a Banana
tanoku
95
10k
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!