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
async 完全理解 - 全ての async は Promise に通ず / Guide to async, await
Search
saiya_moebius
December 04, 2020
Programming
1
460
async 完全理解 - 全ての async は Promise に通ず / Guide to async, await
saiya_moebius
December 04, 2020
Tweet
Share
More Decks by saiya_moebius
See All by saiya_moebius
エムスリーの Over 300 マイクロサービスを支えるマルチクラウドのネットワーク設計 / M3 cloud network infrastructure for over 1000 microservices
saiya_moebius
0
250
TypeScript の型システム / Type system of the TypeScript
saiya_moebius
10
3k
垂直スケールの果ての db.r4.16xlarge で得た教訓 / What happened on vertically scaled 16xlarge DB
saiya_moebius
4
3.7k
DNS を 15 分で雑に知る / grasp DNS in 15 minutes
saiya_moebius
0
98
分散トレーシングの技術選定・OSS 貢献, Stackdriver Trace での性能可視化・改善 / Distributed Tracing case study
saiya_moebius
10
6k
RDBMS in Action
saiya_moebius
56
20k
Kubernetes こわくないよ!
saiya_moebius
1
5.4k
Compiler/JIT optimizations & escape analysis
saiya_moebius
2
300
How to setup Gradle to improve legacy Java system
saiya_moebius
1
2.4k
Other Decks in Programming
See All in Programming
What We Can Learn From OSS
inouehi
0
420
Goのエラースタックトレースの歴史と今後
sonatard
8
1.4k
2 週間で Twitter Bot を作ってみた
contour_gara
0
390
ONE WEDGE_company_guide
1wedge_one
0
480
Code Reviews
bkuhlmann
4
890
Netty Chicago Java User Group 2024-04-17
sullis
0
170
VS Code をプロダクトにどう取り込むか
onomax
1
360
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
170
エンターテイメント業界で利用されるAWS
demuyan
0
210
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
380
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
700
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
530
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
42
12k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
78
42k
Into the Great Unknown - MozCon
thekraken
10
990
4 Signs Your Business is Dying
shpigford
175
21k
How to Ace a Technical Interview
jacobian
272
22k
Statistics for Hackers
jakevdp
789
220k
Music & Morning Musume
bryan
41
5.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Thoughts on Productivity
jonyablonski
58
3.8k
The Pragmatic Product Professional
lauravandoore
25
5.8k
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
Transcript
None
None
None
Promise Deferred Objects async await Promise async await
None
Promise<T> ( ) ( ) resolve(T) Promise reject(any) Promise then(f,
f) , ,
Promise<T> ( ) ( ) resolve(T) Promise reject(any) Promise then(f,
f) , ,
async return throw await const value = await ; console.debug(value);
.then((value) => { console.debug(value); });
None
None
None
const promise = new Promise(); // ... ... promise.resolve( );
/* */ promise.reject( ); new Promise((resolve, reject) => { // ... ... resolve( ); /* */ reject( ); });
// Promise let resolve, reject; new Promise((_resolve, _reject) => {
// resolve, reject resolve = _resolve; reject = _reject; }); resolve( ); /* */ reject( ); // ↑ ...
function () { // Promise ... const promise = new
Promise(); // ... ( promise.resolve ) ... return promise; } const promise = (); promise.resolve(null); // resolve
function () { // Promise return new Promise((resolve, reject) =>
{ // ... ( resolve ) ... }); } const promise = (); // ↑ resolve
function (props) { // const hoge = props.something.foobar(); // Promise
... const promise = new Promise(); // ... ( promise.resolve ) ... return promise; } resolve( ) reject( )
None
function () { /* ※1 */ return new Promise((resolve, reject)
=> { // reject( ) }); } const promise = (); // ↑ Promise reject ※1
promise.then .then((result) => { return (); // Promise }).then((result) =>
{ // result === });
Promise.all(Promise<T>[]): Promise<T[]> Promise.race(Promise<T>[]): Promise<T> promise.catch(f)
function myFunction() { A().then((resultA) => { if (resultA === "hoge")
{ B().then((resultB) => { if (resultB === "huga") C(); }); } else { D().then((resultC) => { if (resultC === "piyo") E(); }); } }); }
None
None
async return throw await const value = await ; console.debug(value);
.then((value) => { console.debug(value); });
await // async function myFunction() { if (await A() ===
"hoge") { if (await B() === "huga") C(); } else { if (await D() === "piyo") E(); } } await then
None
Promise Promise.all Promise.race await Promise.all( 1(), 2(), ...) Promise
async await async Promise Promise await await
None
None
async await function hoge() { const async = 1; const
await = 2; console.log(async, await); // it works } async await async function() { ... } async
await async function myFunction() { await 1(); // 1().then(...) 1();
2(); // await 2(); await 3(); // 3().then(...) } 2 no-floating-promises
await Promise.resolve(Promise.resolve(123)); // Promise.resolve(123) 123 // Promise.resolve Promise
fulfill reject resolve Promise.reject(e) Promise.resolve(value) fulfill resolve reject
new Promise Promise. Promise
Promise Promise Promise = undefined; // Promise.resolve(1234); // await (async()
=> 123)(); // async await Promise Promise ZoneAwarePromise Promise Zone async await Promise.
await then await 14.6.13 Runtime Semantics: Evaluation 25.5.5.3 AsyncFunctionAwait (
value ) 25.4.5.3.1 PerformPromiseThen
await