Created
April 2, 2020 11:29
-
-
Save xodhx4/194fc29cfda9cff846e56ac394860edb to your computer and use it in GitHub Desktop.
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function resolveAfter3Seconds() { // 3초 동안 대기하게 함 | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve('resolved1'); | |
}, 3000); | |
}); | |
} | |
function resolveAfter2Seconds() { // 2초 동안 대기하게 함 | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve('resolved2'); | |
}, 2000); | |
}); | |
} | |
async function printAsync1() { | |
console.log('calling1'); | |
const result = await resolveAfter3Seconds(); | |
return result; | |
} | |
async function printAsync2() { | |
console.log('calling2'); | |
const result = await resolveAfter2Seconds(); | |
return result; | |
} | |
const result1 = await printAsync1(); // 실제로는 불가능함 | |
console.log(result1); | |
const result2 = await printAsync2(); // 실제로는 불가능함 | |
console.log(result2); | |
// > "calling1" | |
// > "resolved1" | |
// > "calling2" | |
// > "resolved2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment