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
870
1
Share
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.7k
gotandajs-11-nodejs-recursive-readdir
arayaryoma
2
520
What about Temporal in JavaScript
arayaryoma
5
1.6k
var, let, const and immutable of JavaScript
arayaryoma
0
290
2018-07-31-angular-tips
arayaryoma
1
140
Other Decks in Programming
See All in Programming
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
140
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
180
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
140
GitHubCopilotCLIをはじめよう.pdf
htkym
0
320
【26新卒研修資料】TDD実装演習
dip_tech
PRO
0
170
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
120
ハーネスエンジニアリングにどう向き合うか 〜ルールファイルを超えて開発プロセスを設計する〜 / How to approach harness engineering
rkaga
28
19k
Agentic Elixir
whatyouhide
0
440
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
220
実用!Hono RPC2026
yodaka
2
300
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.6k
t *testing.T は どこからやってくるの?
otakakot
1
910
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
How to build a perfect <img>
jonoalderson
1
5.5k
Building AI with AI
inesmontani
PRO
1
970
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
140
Speed Design
sergeychernyshev
33
1.6k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Designing for Performance
lara
611
70k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
170
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.4k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
190
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
280
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に関しては使えるようになるかかなり怪しい・・・