Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nathanielmillard/037b329e0dfb5e85e045cabcf8982aff to your computer and use it in GitHub Desktop.
Save nathanielmillard/037b329e0dfb5e85e045cabcf8982aff to your computer and use it in GitHub Desktop.

Don't forget to call for help if you need it in your breakout rooms!

Warm Up

  • What does the async keyword do?

Its a key word that comes before declaring a function that allows a function to be asyncronous (use the await key word). Makes your functions return a promise as opposed to a value

  • What does the await keyword do?

It pauses the function, and only continues after what's being resolved after await. It allows us to access a resolved value of a promise. Allows us to block call stack of function with async code Allows us to run async code as though it were synconous "Don't run anything bellow this promise we are awaiting until that promise has resolved"

  • Convert this function to use async / await: ( https://repl.it/@khalidwilliams/2006M3-async-await-practice )

    // https://api.adviceslip.com/
    
    function getAdvice () {
    	fetch('https://api.adviceslip.com/advice')
    		.then(response  => response.json())
    		.then(adviceSlip => console.log(adviceSlip.advice))
    		.catch(error => console.error(error));
    }
    
    getAdvice();
  • Why would you mock a network request in a test?

Gives us control of the data being recieved for a component, and saves us time and money by not actullly doing real requests.

Hint: Don't be afraid to look at documentation for any of these questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment