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...
Search
saiya_moebius
December 04, 2020
Programming
1
530
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
330
TypeScript の型システム / Type system of the TypeScript
saiya_moebius
10
3.3k
垂直スケールの果ての db.r4.16xlarge で得た教訓 / What happened on vertically scaled 16xlarge DB
saiya_moebius
4
4k
DNS を 15 分で雑に知る / grasp DNS in 15 minutes
saiya_moebius
0
140
分散トレーシングの技術選定・OSS 貢献, Stackdriver Trace での性能可視化・改善 / Distributed Tracing case study
saiya_moebius
10
6.7k
RDBMS in Action
saiya_moebius
56
25k
Kubernetes こわくないよ!
saiya_moebius
1
5.7k
Compiler/JIT optimizations & escape analysis
saiya_moebius
2
410
How to setup Gradle to improve legacy Java system
saiya_moebius
1
2.7k
Other Decks in Programming
See All in Programming
Serving TUIs over SSH with Go
caarlos0
0
650
Contribute to Comunities | React Tokyo Meetup #4 LT
sasagar
0
600
GitHub Copilot for Azureを使い倒したい
ymd65536
1
330
The Nature of Complexity in John Ousterhout’s Philosophy of Software Design
philipschwarz
PRO
0
170
M5UnitUnified 最新動向 2025/05
gob
0
140
ComposeでのPicture in Picture
takathemax
0
140
音声プラットフォームのアーキテクチャ変遷から学ぶ、クラウドネイティブなバッチ処理 (20250422_CNDS2025_Batch_Architecture)
thousanda
0
420
マイコンでもRustのtestがしたい/KernelVM Kansai 11
tnishinaga
0
880
カオスに立ち向かう小規模チームの装備の選択〜フルスタックTSという装備の強み _ 弱み〜/Choosing equipment for a small team facing chaos ~ Strengths and weaknesses of full-stack TS~
bitkey
1
140
The New Developer Workflow: How AI Transforms Ideas into Code
danielsogl
0
120
カウシェで Four Keys の改善を試みた理由
ike002jp
1
140
一緒に働きたくなるプログラマの思想 #QiitaConference
mu_zaru
81
21k
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
245
12k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Designing for humans not robots
tammielis
253
25k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
179
53k
Navigating Team Friction
lara
185
15k
The Invisible Side of Design
smashingmag
299
50k
Into the Great Unknown - MozCon
thekraken
38
1.8k
How STYLIGHT went responsive
nonsquared
100
5.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
105
19k
Scaling GitHub
holman
459
140k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
33k
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