# Javascript Async, Await 심화
```javascript
// 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' 카테고리의 다른 글
Replace Tag(Script & div & B tag to strong) (0) | 2019.07.12 |
---|---|
bind click event loop index (0) | 2019.07.12 |
Javascript Async return Promise For await (0) | 2019.07.12 |
ECMA6 (0) | 2019.01.30 |
Javascript Async, Await 심화 (0) | 2019.01.30 |
댓글