Created
April 2, 2020 11:29
-
-
Save xodhx4/5f9d0e5c00a311d60bad95297df65d62 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 returnDataAfter2Seconds() { // 2초 뒤에 값을 돌려주는 IO 작업 | |
return new Promise(resolve => { // 2초 동안 Blocking 되지 않기 위해 Promise 객체를 return 한다 | |
setTimeout(() => { | |
resolve('data'); | |
}, 2000); | |
}); | |
} | |
f = returnDataAfter2Seconds(); | |
// const data = f.result(); Blocking IO이기 때문에 js에는 존재하지 않는다 | |
f.then((data) => console.log(data)); // 대신 콜백 함수를 넘겨서, 결과값을 매개변수로 받는다 | |
// > "data" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment