0.4.6.1: Async Await
Learning Objectives
Introduction
// myFunc returns the return value of myFunc, currently undefined
const myFunc = () => {
axios.get("foobar.com").then((data) => {
// Do something with data after response received
console.log(data);
});
};// myFunc returns a promise due to the async keyword
// The promise resolves to the return value of myFunc
const myFunc = async () => {
const data = await axios.get("foobar.com");
// Do something with data after response received
console.log(data);
};Example: Async-await with pg
pgExample: Catch errors with async-await
Example: Async-await does not pause programs, only code in current function
Example: Async-await works with all promises, including the promise returned by Promise.all
Promise.all