# Javascript Async, Await 심화

# Javascript Async, Await 심화

by jihoon kim

HTML

<h1>Javascript Async, Await 심화</h1>

<pre id="contents">
==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== 
// wait ms milliseconds
function wait(ms) {
  return new Promise(r => setTimeout(r, ms));
}

async function hello() {
  await wait(1500);
  return 'world';
}
hello()
.then(function(r,j){ 
    console.info(r,j);
})
.catch(function(e){
    console.info(e); 
});

==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== 
// wait ms milliseconds
function wait(ms) {
  return new Promise(r => setTimeout(r, ms));
}
async function foo() {
//  await wait(500);
  throw Error('bar');
}

async function foo() {
//  await wait(500);
  throw {"aError":"aError"}
}

foo()
.then(function(r,j){ 
    console.info(r,j);
})
.catch(function(e){
    console.info(e); 
});

</pre>

<script>
function autolink(id) {
  var container = document.getElementById(id);
  var doc = container.innerHTML;
  var regURL = new RegExp("(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)","gi");
  var regEmail = new RegExp("([xA1-xFEa-z0-9_-]+@[xA1-xFEa-z0-9-]+\.[a-z0-9-]+)","gi");
  return doc.replace(regURL,"<a href='$1://$2' target='_blank'>$1://$2</a>").replace(regEmail,"<a href='mailto:$1'>$1</a>");
}

window.onload = function () {
  var container = document.getElementById("contents");
	container.innerHTML = autolink("contents");
}
</script>