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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Araya
June 06, 2019
Programming
880
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaScript Promise API in 2019
Araya
June 06, 2019
More Decks by Araya
See All by Araya
Performance and cache strategy at NIKKEI
arayaryoma
0
2.9k
gotandajs-11-nodejs-recursive-readdir
arayaryoma
2
530
What about Temporal in JavaScript
arayaryoma
5
1.7k
var, let, const and immutable of JavaScript
arayaryoma
0
300
2018-07-31-angular-tips
arayaryoma
1
140
Other Decks in Programming
See All in Programming
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
1k
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
210
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
270
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
470
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
0
450
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
230
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
140
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
2
500
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
3
440
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.3k
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.8k
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
120
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
970
Building Adaptive Systems
keathley
44
3.2k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
710
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Writing Fast Ruby
sferik
630
63k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
190
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
310
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
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に関しては使えるようになるかかなり怪しい・・・