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
いまさら振り返るPromise
Search
chikoski
July 23, 2017
Technology
1
530
いまさら振り返るPromise
chikoski
July 23, 2017
Tweet
Share
More Decks by chikoski
See All by chikoski
20210825_ossx
chikoski
0
280
festudy02-wasm
chikoski
1
950
An overview of WebAssembly; how it is used, created, and applied?
chikoski
1
670
Functions in JavaScript
chikoski
1
1.1k
20171018-WASM
chikoski
2
1.3k
20171002-wejs
chikoski
1
540
20170924-html5conference-wasm
chikoski
5
10k
Equivalence_in_JS
chikoski
0
1.4k
Design and Implementation of Tech Talks
chikoski
0
110
Other Decks in Technology
See All in Technology
Building Scalable Backend Services with Firebase
wisdommatt
0
110
カップ麺の待ち時間(3分)でわかるPartyRockアップデート
ryutakondo
0
140
あなたの人生も変わるかも?AWS認定2つで始まったウソみたいな話
iwamot
3
850
「隙間家具OSS」に至る道/Fujiwara Tech Conference 2025
fujiwara3
7
6.4k
2025年の挑戦 コーポレートエンジニアの技術広報/techpr5
nishiuma
0
140
【NGK2025S】動物園(PINTO_model_zoo)に遊びに行こう
kazuhitotakahashi
0
220
Git scrapingで始める継続的なデータ追跡 / Git Scraping
ohbarye
5
490
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
170
#TRG24 / David Cuartielles / Post Open Source
tarugoconf
0
580
AWSサービスアップデート 2024/12 Part3
nrinetcom
PRO
0
140
エンジニアリングマネージャー視点での、自律的なスケーリングを実現するFASTという選択肢 / RSGT2025
yoshikiiida
4
3.6k
20250116_自部署内でAmazon Nova体験会をやってみた話
riz3f7
1
100
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Done Done
chrislema
182
16k
Statistics for Hackers
jakevdp
797
220k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
How GitHub (no longer) Works
holman
312
140k
A Tale of Four Properties
chriscoyier
157
23k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Fireside Chat
paigeccino
34
3.1k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Side Projects
sachag
452
42k
Scaling GitHub
holman
459
140k
Transcript
いまさら振り返るPromise N.Shimizu (
[email protected]
)
Promise: いずれされる処理を表すオブジェクト https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise 1SPNJTF UIFO GVM'JMMFE UIFO SFKFDUFE DBUDI
SFKFDUFE 1SPNJTF Pending Fulfill Reject Return Return
Promise chain GFUDI IUUQTFYBNQMFDPNFOEQPJOUTPNFBDUJPO UIFO SFTQPOTFSFTQPOTFKTPO FSSOPUJGZ&SSPS FSS
UIFO EBUBEBUBMFOHUI EBUB1SPNJTFSFKFDU OPEBUB UIFO EBUBSFOEFS%BUB EBUB FSSOPUJGZ/P%BUB
処理を始めるところと、結果を利用するところを分けられる EP4PNFUIJOH QBSBN SFTQPOTF\ JG SFTQPOTFFSS \ SFUVSOIBOEMF&SSPS SFTQPOTFFSS
^ EP" EP# EP$ EP% DPOTVNF SFTQPOTFSFTVMU ^ DPOTUQEP4PNFUJOH QBSBN EP" EP# EP$ EP% QUIFO DPOTVNF DBUDI IBOEMF&SSPS
Promise: 条件分岐の一種 https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise 1SPNJTF UIFO GVM'JMMFE UIFO SFKFDUFE DBUDI
SFKFDUFE 1SPNJTF Pending Fulfill Reject Return Return
直列化 UFTU" UIFO UFTU# UIFO TVDDFTT DBUDI GBJM
<UFTU" UFTU#> SFEVDF QSP GVOD QSPUIFO GVOD UIFO TVDDFTT DBUDI GBJM 1SPNJTFBMM <UFTU" UFTU# > UIFO TVDDFTT DBUDI GBJM 㛈ᏁҶ⼊ҿӶӔҮ UFTU" UFTU# TVDDFTT GBJM F T T F
並列化 UFTU" DBUDI UFTU# UIFO TVDDFTT DBUDI GBJM
1SPNJTFSBDF <UFTU" UFTU# > UIFO TVDDFTT DBUDI GBJM 㛈ᏁҶ⼊ҿӶӔҮ UFTU" UFTU# TVDDFTT GBJM F T T F
エラー処理を本筋と分けて実装できる MFUSFTVMUEP4PNFUIJOH JG SFTVMUOVMM \ SFTVMUEFGBVMU7BMVF ^ DPOTVNF
SFTVMU EP4PNFUIJOH DBUDI FSSEFGBVMU7BMVF UIFO DPOTVNF
Promise非対応のPromise対応にするには GVODUJPOBEE B C \ SFUVSOB C ^ GVODUJPOQSPNJTFE"EE B
C \ SFUVSO1SPNJTFSFTPMWF B C ^ QSPNJTFE"EE UIFO JDPOTPMFMPH
Promise非対応のPromise対応にするには GVODUJPOBEE B C \ JG B]]C \ UISPXOFX&SSPS *OWBMJEQBSBNFUFS
^ SFUVSOB C ^ GVODUJPOQSPNJTFE"EE B C \ USZ\SFUVSO1SPNJTFSFTPMWF BEE B C ^ DBUDIFSS\SFUVSO1SPNJTFSFKFDU FSS ^ ^
Promise非対応のPromise対応にするには DPOTUGTSFRVJSF GT GVODUJPOSFBE GJMF \ SFUVSOOFX1SPNJTF SFTPMWF SFKFDU
\ GTSFBE'JMF GJMF FSS EBUB \ FSS SFTPMWF FSS SFKFDU EBUB ^ ^ ^
Promise非対応のPromise対応にするには GVODUJPOBEE0OF OVNCFST \ DPOTUSFTVMU<> GPS DPOTUOVNPGOVNCFST \ SFTVMUQVTI OVN
^ ^ GVODUJPOQSPNJTFE"EE0OF OVNCFST \ SFUVSO1SPNJTFBMM OVNCFSTNBQ J1SPNJTFSFTPMWF J ^
Anti-pattern: ネストしたPromise EP" UIFO SFTVMU"\ EP# UIFO SFTVMU#DPOTVNF SFTVMU" SFTTVMU#
^ 1SPNJTFBMM <EP" EP# > UIFO SFTVMUTDPOTVNF SFTVMUT<> SFTVMU<> http://taoofcode.net/promise-anti-patterns/
Anti-pattern: 続かないチェーン GVODUJPOEP4PNFUIJOH \ DPOTUQSPNJTFEP" QSPNJTFUIFO SFTVMUDPOTVNF SFTVMU
SFUVSOQSPNJTF ^ GVODUJPOEP4PNFUIJOH \ SFUVSOEP" UIFO SFTVMUDPOTVNF SFTVMU ^ http://taoofcode.net/promise-anti-patterns/