async-await
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
resolveAfter2Seconds()
.then(
resolved => {
console.log(resolved);
return 'done';
}
);
async function asyncCall() {
console.log(await resolveAfter2Seconds(););
return 'done'
}
asyncCall();
// .then() 사용가능. async 함수의 반환값은 promise기 때문이다.왜 async/await가 더 나을까?
참고
Last updated
Was this helpful?