본문 바로가기

Javascript Async, Await 심화

web/javascript by 낼스 2019. 1. 30.

Javascript Async, Await 심화

==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== 
// 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); 
});

'web > javascript' 카테고리의 다른 글

Javascript Async return Promise For await  (0) 2019.07.12
ECMA6  (0) 2019.01.30
Javascript arrow function expression  (0) 2019.01.30
ES2015(ES6) Module System  (0) 2019.01.30
Javascript Template literals  (0) 2019.01.30

댓글