Skip to content

Instantly share code, notes, and snippets.

@xodhx4
Created April 2, 2020 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xodhx4/5f9d0e5c00a311d60bad95297df65d62 to your computer and use it in GitHub Desktop.
Save xodhx4/5f9d0e5c00a311d60bad95297df65d62 to your computer and use it in GitHub Desktop.
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
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