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
SwiftのAsync / Awaitについて
Search
Takaaki Tanaka
April 14, 2018
Technology
0
190
SwiftのAsync / Awaitについて
第1回 HAKATA.swift ~福岡でSwiftの勉強会~
Takaaki Tanaka
April 14, 2018
Tweet
Share
More Decks by Takaaki Tanaka
See All by Takaaki Tanaka
製造の課題に立ち向かう Manufacturing Data Engine と Manufacturing Connect の ご紹介
kongmingstrap
0
620
Tellus の衛星データを見てみよう #mf_fukuoka
kongmingstrap
0
590
JAWS-UG 福岡 #16 re:Invent 現地に行った人のお話 #jawsugfuk #jawsug
kongmingstrap
0
490
AppMod の開発のイマを知るために現地に潜入した私が見たものは・・・? #GoogleCloudNext
kongmingstrap
0
540
Kong Gateway から読みとく、 API統合・API連携サービスの最新情報 #devio2023
kongmingstrap
0
1.5k
Cloud Run に憧れて Google Cloud を推進している話 / CX事業本部で使われている技術
kongmingstrap
0
210
AWS / Google Cloud / Azure それぞれの推しサービス.pdf
kongmingstrap
0
1.3k
CPUブーストの話
kongmingstrap
0
53
私のAWS愛を聞け! ~ここが好きだよStep Functions~ #devio2022
kongmingstrap
0
1.1k
Other Decks in Technology
See All in Technology
Can We Measure Developer Productivity?
ewolff
1
150
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
200
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
1.3k
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
660
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
300
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
4
230
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
170
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
9
1.1k
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
GitHub's CSS Performance
jonrohan
1030
460k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Agile that works and the tools we love
rasmusluckow
327
21k
Automating Front-end Workflow
addyosmani
1366
200k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Building Adaptive Systems
keathley
38
2.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
420
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Transcript
SwiftͷAsync / Await ʹ͍ͭͯ ୈ1ճ HAKATA.swift
"CPVUNF
wΫϥεϝιουגࣜձࣾ wϞόΠϧΞϓϦαʔϏε෦ wJ04ΞϓϦΤϯδχΞ wαʔόʔαΠυΞϓϦΤϯδχΞ wαʔόʔϨε։ൃ෦ wΞϓϦέʔγϣϯΤϯδχΞ ాத໌ @kongmingtrap
wΫϥεϝιουגࣜձࣾ wϞόΠϧΞϓϦαʔϏε෦ wJ04ΞϓϦΤϯδχΞ wαʔόʔαΠυΞϓϦΤϯδχΞ wαʔόʔϨε։ൃ෦ wΞϓϦέʔγϣϯΤϯδχΞ ాத໌ @kongmingtrap
wΫϥεϝιουגࣜձࣾ wϞόΠϧΞϓϦαʔϏε෦ wJ04ΞϓϦΤϯδχΞ wαʔόʔαΠυΞϓϦΤϯδχΞ wαʔόʔϨε։ൃ෦ wΞϓϦέʔγϣϯΤϯδχΞ ాத໌ @kongmingtrap :".-༑ୡʂʂ
Ϟνϕʔγϣϯ
None
ձࣾͷۚͰߦ͘ ւ֎ΧϯϑΝϨϯε ࠷ߴͩͥʜ
4XJGUͷ "TZOD"XBJUʹ͍ͭͯ
Ϟνϕʔγϣϯ
IUUQTBXTBNB[PODPNKQBCPVUBXTXIBUTOFXBXTMBNCEB TVQQPSUTOPEFKT
IUUQTBXTBNB[PODPNKQBCPVUBXTXIBUTOFXBXTMBNCEB TVQQPSUTOPEFKT
ͳΔ΄Ͳ
4XJGU Ͳ͏ͳ͍ͬͯΔΜͩΖ͏ʁ
"TZOD"XBJUGPS4XJGU
"TZOD"XBJUGPS4XJGU
എܠ
ඇಉظॲཧʹ·ͭΘΔ ՝ͷʑ
"TZOD"XBJUGPS4XJGU
"TZOD"XBJUGPS4XJGU ඇಉظॲཧΛͭͳ͛ཧ߹ ͷίʔϧόοΫࠈ
"TZOD"XBJUGPS4XJGU
"TZOD"XBJUGPS4XJGU ΤϥʔϋϯυϦϯ άͰͷίʔϧόο Ϋࠈ
"TZOD"XBJUGPS4XJGU
"TZOD"XBJUGPS4XJGU ͖݅Ͱඇಉظॲཧ Λ࣮ࢪ͍ͨ͠߹ɺେ ͷ߹ɺίʔυʹ ΫϩʔδϟΛॻ͘͜ͱ ʹͳΔ
"TZOD"XBJUGPS4XJGU
"TZOD"XBJUGPS4XJGU ޙͷॲཧͰHVBSEͳͲͰ ฦΔͷߟྀΛΕͯ͠ ·͏ ͦͦσόοά͠ਏ͍
"TZOD"XBJUGPS4XJGU
"TZOD"XBJUGPS4XJGU ʢϥτφʔࢯͷܦݧଇͱલஔ͖ͭͭ͠ʜʣ ඇಉظ"1*Λ࡞ͬͯɺଟ͘ͷ߹6*ͷߋ৽ͳͲ ͕བྷΉͨΊɺಉظಈ࡞Ͱߦ͏͜ͱ͕ଟ͍
"TZOD"XBJUGPS4XJGU
"TZOD"XBJUGPS4XJGU ࠶։ՄೳͳॲཧΛඳ͖͍ͨ࣌ɺ4XJGUͷ߹ͩͱɺ ஈ֊తʹΛੜ͢ΔͷΛͱͯ͠ఆٛ͢Δඞཁ͕ ͋Δ
"TZOD"XBJU
wඇಉظॲཧͷߏจ w1SPNJTFΛ؆ܿʹهड़Ͱ͖ΔΑ͏ʹͨ͠ w༷ʑͳݴޠʹΤοηϯε͕औΓࠐ·Ε͍ͯ Δʢ+BWB4DSJQUɺ$ɺ1ZUIPOɺ3VTUʜʣ "TZOD"XBJU
ଞͷݴޠͷඇಉظॲཧ
wඇಉظॲཧͷ࠷ऴతͳࣦྃ͘͠ഊΛ ද͢ΦϒδΣΫτ w݁ՌΛUIFOϝιουͳͲͰνΣΠϯͤ͞Δ 1SPNJTF
1SPNJTF doSomething().then(function(result) { return doSomethingElse(result); }) .then(function(newResult) { return doThirdThing(newResult);
}) .then(function(finalResult) { console.log('Got the final result: ' + finalResult); }) .catch(failureCallback);
wऴ͍ྃͯ͠Δ͔Ͳ͏͔Θ͔Βͳ͍ॲཧ݁Ռ ΛநԽͨ͠ܕ w'VUVSFະདྷͷ݁ՌΛද͢ܕ wจࣈ௨Γɺ૬खʢॲཧ͢Δଆʣʹʮະདྷʯ Λୗ͢ 'VUVSF
'VUVSF val f: Future[List[String]] = Future { session.getRecentPosts } f
onFailure { case t => println("Τϥʔ͕ൃੜͨ͠: " + t.getMessage) } f onSuccess { case posts => for (post <- posts) println(post) }
wඇಉظͰฦ͞ΕΔΛड͚ΔͨΊͷߏจ "XBJU function resolveAfter2Seconds(x) { return new Promise(resolve => {
setTimeout(() => { resolve(x); }, 2000); }); } async function f1() { var x = await resolveAfter2Seconds(10); console.log(x); // 10 } f1();
wඇಉظͰΛฦ͢͜ͱΛ໌ࣔ͢Δߏจ "TZOD GVODUJPOSFTPMWF"GUFS4FDPOET \ SFUVSOOFX1SPNJTF SFTPMWF\ TFU5JNFPVU \ SFTPMWF SFTPMWFE
^ ^ ^ BTZODGVODUJPOBTZOD$BMM \ DPOTPMFMPH DBMMJOH WBSSFTVMUBXBJUSFTPMWF"GUFS4FDPOET DPOTPMFMPH SFTVMU FYQFDUFEPVUQVUSFTPMWFE ^ BTZOD$BMM
"TZOD function resolveAfter2Seconds(x) { return new Promise(resolve => { setTimeout(()
=> { resolve(x); }, 2000); }); } async function add1(x) { const a = await resolveAfter2Seconds(20); const b = await resolveAfter2Seconds(30); return x + a + b; } add1(10).then(v => { console.log(v); // 4ඵޙʹ60Λදࣔ͠·͢ɻ });
4XJGUͰ ࣮ݱ͠Α͏ͱ͢Δͱ
"TZOD"XBJUGPS4XJGU "TZODͷߏจʹ͍ͭͯ
"TZOD"XBJUGPS4XJGU "XBJUͷߏจʹ͍ͭͯ
"TZOD"XBJUGPS4XJGU #FGPSF
"TZOD"XBJUGPS4XJGU "GUFS
✌ Т✌ ࡾ✌ Т ✌ࡾ ✌Т ✌
"TZOD"XBJUGPS4XJGU 'VUVSF
"TZOD"XBJUGPS4XJGU 'VUVSF
͍͔ͭΒ͑Δʁ
"TZOD"XBJUGPS4XJGU
None
IUUQTRJJUBDPNLPIFSJUFNTCFBFD
None
$PODVSSFODZJO 4XJGU0OFBQQSPBDI
$PODVSSFODZJO4XJGU0OFBQQSPBDI
IUUQTXXXTMJEFTIBSFOFUZVHPMGQSFQBSJOHGPSEJTUSJCVUFETZTUFNGBJMVSFT VTJOHBLLBTDBMBNBUTVSJ
None
"QQFOEJY
w "TZOD"XBJUGPS4XJGU w $PODVSSFODZJO4XJGU0OFBQQSPBDI w 1SPQPTBMʹࡌ͍ͬͯͳ͍4XJGUͷBTZODBXBJU͕ૉΒ͠ ͍ͱࢥ͏ཧతഎܠ w "LLBJO"DUJPOXPSLTIPQ4DBMB.BUTVSJ w
1SFQBSJOHGPSEJTUSJCVUFETZTUFNGBJMVSFTVTJOHBLLB 4DBMB.BUTVSJ ࢀߟจݙ
None