Skip to content

Instantly share code, notes, and snippets.

@xodhx4
Created April 2, 2020 11:29
Show Gist options
  • Save xodhx4/c287acff3525c5d0cc16b57a7fc942ee to your computer and use it in GitHub Desktop.
Save xodhx4/c287acff3525c5d0cc16b57a7fc942ee 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 dataExpected = f.then((data) => {return data;}); // 결과값을 돌려받기 기대한다
console.log(dataExpected) // Promise를 리턴한다
// > [object Promise]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment