Functions prefixed with the
async keyword implicitly return a promise. When the function returns a value the promise is fulfilled.
The async implementation of
foo above is equivalent to the below implementation that explicitly returns a
await keyword to stop a function from continuing until an
async function completes.
Think of a
Promise like a container for a value that can only be known at some point in the future (like the result of a network call or reading a file from disk). They exist in one of three states:
Promise has callback functions that are executed when its state changes to handle success or failure. These callbacks can themselves be a
Promise allowing for
Promise’s to be chained.
resolve changes the promises state…