JavaScript async ์™€ await

async.awaitโ€‹โ€‹

promise๋ฅผ ์ข€ ๋” ๊ฐ„ํŽธํ•˜๊ณ  ๋™๊ธฐ์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š”๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ๋Š”๊ฒƒ

async

// async & await 
// clear style of using promise :)
// promise๋ฅผ ์ข€ ๋” ๊น”๋”ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์คŒ 

// 1.async 
async function fetchUser() {
   //do network reqeust in 10 secs....
    return 'ellie';
}
// async ๋ผ๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด promise๋ž‘ ๋˜‘๊ฐ™์€ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•จ

const user = fetchUser();
user.then(console.log);
console.log(user);

await

useful promise APIs

Last updated

Was this helpful?