Skip to content

Instantly share code, notes, and snippets.

@rogerwschmidt
Last active September 22, 2022 11:52
Show Gist options
  • Save rogerwschmidt/4921411a7738a172a2f7eae72a3ae8c6 to your computer and use it in GitHub Desktop.
Save rogerwschmidt/4921411a7738a172a2f7eae72a3ae8c6 to your computer and use it in GitHub Desktop.

Promises Instructor Notes

Objectives

  • Describe how asynchronus code differs from synchronous code
  • Create chained asynchronous events
  • Explain what the drawbacks of callbacks are when handling chained async events
  • Use Promises to flatten async events
  • Use Promises to return async event from a function

Describe how asynchronus code differs from synchronous code

What is the output of the following code?

console.log(1)
console.log(2)
setTimeout(function(){
  console.log(3)
},1000)
console.log(4)
console.log(5)

Create chained asynchronous events

Use setTimeout to create a countdown from 5 in real time

Explain what the drawbacks of callbacks are when handling chained async events

What is the callback pyramid of death? Why is it a bad pattern?

Use Promises to flatten async events

Use the following example code to create a countdown -> https://repl.it/repls/DecentLopsidedSupport

Use Promises to return async event from a function

Create a function named countFrom5 that counts down from 5 and returns a promise.

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