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);
});
댓글