Bonus: ES8 Async& Await
Bonus: ES8 Async & Await
Shan-Hung Wu & DataLab CS, NTHU
Outline
? ES6 Promises ? ES8 Async & Await ? Pitfalls
2
// in method1()
const p = new Promise((resolve, reject) => {
... // do asynchronous job here
if (success) resolve(data); else reject(err);
ES6 Promise
});
return p;
// in method2(p) const p2 = p.then(data => {
? A value available in the future
... // process data return data2
? Separation of
}); // always returns a new Promise concerns
return p2;
? Handlers can be
// in method3(p2)
written in
p2.then(data2 => {
... process data2 }).catch(err => {
different places
? Use arrow func
for this ... // handle err
}); // always returns a new Promise
3
resolve() reject()
return
throw
Execution Flow
? Chain then and/or catch as long as you like
? Reject mode:
? throw new Error()
? Resolve mode:
? return
return
throw
4
Axios and AJAX Requests
const axios = require('axios');
// GET request axios.get('...url...').then(res => {
res.status // HTTP response code (e.g., 200, 401) res.data // object parsed from HTTP response body res.headers // HTTP presonse headers }).catch(err => { console.log(err.response.status); });
// POST request axios.post('...url...', {
... // request body }).then(...).catch(...);
? Requests can be canceled
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- react js course a2n academy
- async await
- rust s journey to async await qcon
- a study and toolkit for asynchronous programming in c
- best practices for c async await alexandru ioan cuza university
- reactjs
- async await internals
- bonus es8 async await
- async asynchronous code constructs generators yield async await
- asynchronous programming with async and await 1 await operator 12 async
Related searches
- va bonus entitlement worksheet 2019
- 200 cash back bonus offers
- 200 cash bonus credit card
- cash bonus credit cards
- va loan bonus entitlement calculator
- va bonus entitlement worksheet fillable
- va bonus entitlement calculation worksheet
- va bonus entitlement calculator
- best credit card sign up bonus 2019
- 300 bonus for opening checking
- wells fargo 400 bonus offer
- 75000 bonus miles credit card