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
JavaScript Promise API in 2019
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Araya
June 06, 2019
Programming
1
860
JavaScript Promise API in 2019
Araya
June 06, 2019
Tweet
Share
More Decks by Araya
See All by Araya
Performance and cache strategy at NIKKEI
arayaryoma
0
2.6k
gotandajs-11-nodejs-recursive-readdir
arayaryoma
2
510
What about Temporal in JavaScript
arayaryoma
5
1.6k
var, let, const and immutable of JavaScript
arayaryoma
0
280
2018-07-31-angular-tips
arayaryoma
1
130
Other Decks in Programming
See All in Programming
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
270
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.1k
AI & Enginnering
codelynx
0
110
dchart: charts from deck markup
ajstarks
3
990
CSC307 Lecture 04
javiergs
PRO
0
660
CSC307 Lecture 07
javiergs
PRO
0
550
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.5k
CSC307 Lecture 02
javiergs
PRO
1
780
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
CSC307 Lecture 05
javiergs
PRO
0
500
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
Mobile First: as difficult as doing things right
swwweet
225
10k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
0
3.4k
It's Worth the Effort
3n
188
29k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
170
A Soul's Torment
seathinner
5
2.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
36k
Crafting Experiences
bethany
1
48
Transcript
Promiseͷ෮शͱ༧श あらや @arayaryoma 2019-06-06 Meguro.es # 21 @ ビザスク たぶん初心者向け
自己紹介 あらや / 阿部 凌磨 @arayaryoma @arayaryoma https://araya.dev Web developer
at 株式会社ヘマタイト JavaScript/TypeScript/Go/Kotlin Angular/React/ReactNative/Next.js/Nest.js
Promise API Promise.all Promise.race Promise.reject Promise.resolve Promise.any Promise.allSettled Promise.try Promise.prototype.catch
Promise.prototype.then Promise.prototype.finally
Promise.resolve(value) 引数で渡された値で解決されたPromiseオブジェクトを返す
Promise.reject(reason) 引数で渡された理由(reason)でリジェクトされたPromiseオブジェクトを返す
Promise.prototype.then(onResolved, onRejected) 第1引数に、Promiseが解決されたとき、第2引数にリジェクトされたときに呼ばれる コールバック関数を受け取る。 Promiseを返す。
Promise.prototype.catch(onRejected) Promiseがリジェクトされたときに呼ばれるコールバック関数を引数で受け取る。 Promiseを返す。 .then(undefined, onRejected)と等価。
Promise.prototype.catch(onRejected) Promiseがリジェクトされたときに呼ばれるコールバック関数を引数で受け取る。 Promiseを返す。 .then(undefined, onRejected)と等価。 then͔ΒcatchνΣΠϯͰ͖Δ
Promise.all([…promises]) 引数で渡されたイテレータブルなオブジェクトの中のすべてのPromiseが解決されたら 解決された単一のPromiseを返す。
Promise.all([…promises]) どれか1つでもリジェクトされたら、 そのreject reasonを持ってリジェクトされる。
Promise.race([…promises]) Promiseのイテレータブルなオブジェクトを受け取る。 受け取ったPromiseのうち、 どれか1つでも解決もしくはリジェクトされたら その状態のPromiseを返す。
Promise.prototype.finally(callback) 解決されたかリジェクトされたかにかかわらず、Promiseが確立されたら、 引数で受け取ったコールバック関数が実行される。 Stage4
Promise.prototype.finally(callback) 確立されたらとりあえずなにか処理をして、それからthenとcatchを処理したい。 Stage4 finallyղܾ͘͠ϦδΣΫτ͞ΕͨΛ࣋ͬͨPromiseΛฦ͢
Promise.allSettled([…promises]) Stage3 allと同じく、Promiseのイテレータブルなオブジェクトを受け取る。 すべてのPromiseが解決もしくはリジェクトされるのを待ち、結果を持ったPromiseの配列を返す。
Promise.any([…promises]) Stage1 Promiseのイテレータブルなオブジェクトを受け取る。 受け取ったPromiseのうち、どれか1つでも解決されたら その解決された値をPromiseとして返す。 すべてのPromiseがリジェクトされたら リジェクト理由の配列を返す。
Promise.any([…promises]) Stage1 Promiseのイテレータブルなオブジェクトを受け取る。 受け取ったPromiseのうち、どれか1つでも解決されたら その解決された値をPromiseとして返す。 すべてのPromiseがリジェクトされたら リジェクト理由の配列を返す。
Promise.try(func) Stage1 引数で受け取ったfuncが同期的に例外を吐いてもPromiseがリジェクトされたものとして扱える。 bluebirdから輸入(?) 最終更新は3年前・・・
Promise.try(func) Stage1
Promise.try(func) Stage1
·ͱΊ PromiseのAPIはresolve, reject, then, catch以外にも、 知っていると便利なものがいくつかあります。 これを踏まえてPromiseで非同期処理を書いているコードを見直すと きれいにまとめられる箇所が見つかるかもしれません。 tryに関しては使えるようになるかかなり怪しい・・・