Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Escape Callback Hell and Enter Callback Heaven ...

Escape Callback Hell and Enter Callback Heaven with Async/Await

JavaScript relies heavily on callbacks for async functions which leads to the infamous 'callback hell'. ES7 is proposing the use of async/await to avoid this. Node.js has already implemented it in version 7.6. I will show you how you can escape from callback hell and reach callback heaven with async await.

Jennifer Bland

September 21, 2017
Tweet

More Decks by Jennifer Bland

Other Decks in Programming

Transcript

  1. The only thing that maters in software is the experience

    of the user Change How I/O Is Handled
  2. Node.js Design Goals No function should direct perform I/O To

    receive info from disk, network or other process, there must be a callback Stream everything; never force the buffering of data Have built-in support for important protocols
  3. z

  4. Async Await Async - declares an asynchronous function Automatically transforms

    a regular function into a Promise When called async functions resolve with whatever is returned in their body Async functions enable the use of await
  5. Async Await Await - pauses the execution of async functions

    When placed in front of a Promise call, await forces the rest of the code to wait until that Promise finishes and returns a result Await works only with Promises, it does not work with callbacks Await can only be used inside async functions