In this section I will be going over just a few very basic examples that involve the use of promsies and the async keyword as a way to create functions.
So here I have a basic example that involves the use of promises and setTimeout.
The async keyword can be used in combination with a function such as an arrow function to declare an async function. Inside the body of the async function the await keyword can be used as a way to pause the execution of the rest of the logic in the function until a function that was called with await is completed. The function that is called with awaite should be a function that will return a promsie or another function created with the async keyword.
The foo function returns a promise that resolves after a delay. When used inside the body of the func async function that execution of code is paused, and thus the string end is not logged to the console until the delay has completed. So this can be thought of as a cleaner style compared to just using promises.
For example take into account the following:
In this example when the heavyAsync function is called it still ends up delaying the whole application. This is because I am still just working with a single event loop.