Async and Await
It has always been the dream of JavaScript developers to handle async functions without the need to write wrappers around them. Then, a new feature was introduced, and that changed everything we know about JavaScript async operations. Consider the code we used in the last exercise:
function getFullRecord(id) { Â Â Â return getProfile(id) Â Â Â Â Â .then(getCart) Â Â Â Â Â .then(getSubscription); }
It is simple enough because we used promise chaining, but it doesn't really tell us anything more than that, and it appears we are just calling a bunch of functions. What if we could have something like this:
function getFullRecord(id) { Â Â Â const profile = getProfile(id); Â Â Â const cart = getCart(id); Â Â Â const subscription = getSubscription(id); Â Â Â return { Â Â Â Â Â ...profile, Â Â Â Â Â cart, Â Â ...