add promise queue
This commit is contained in:
parent
1373f6158c
commit
16cfa3037b
27 changed files with 160 additions and 36 deletions
20
1-js/11-async/07-async-await/01-rewrite-async/task.md
Normal file
20
1-js/11-async/07-async-await/01-rewrite-async/task.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
# Rewrite using async/await
|
||||
|
||||
Rewrite the one of examples from the chapter <info:promise-chaining> using `async/await` instead of `.then/catch`:
|
||||
|
||||
```js run
|
||||
function loadJson(url) {
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (response.status == 200) {
|
||||
return response.json();
|
||||
} else {
|
||||
throw new Error(response.status);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
loadJson('no-such-user.json') // (3)
|
||||
.catch(alert); // Error: 404
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue