Slide 1

Slide 1 text

Escape Callback Hell and Enter Callback Heaven with Async/Await Jennifer Bland

Slide 2

Slide 2 text

Who Am I? www.jenniferbland.com @ratracegrad www.youtube.com/c/JenniferBland [email protected] github.com/jenniferbland

Slide 3

Slide 3 text

IN THE BEGINNING or how did we get here

Slide 4

Slide 4 text

The only thing that maters in software is the experience of the user Change How I/O Is Handled

Slide 5

Slide 5 text

Sample Code

Slide 6

Slide 6 text

CHANGE THE INFRASTRUCTURE non-blocking event loop

Slide 7

Slide 7 text

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 buļ¬€ering of data Have built-in support for important protocols

Slide 8

Slide 8 text

Progression of I/O Handling

Slide 9

Slide 9 text

Sample Code - no waiting

Slide 10

Slide 10 text

Sample Code - callback

Slide 11

Slide 11 text

Sample Code - callback hell

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Promises

Slide 14

Slide 14 text

Chaining Promises

Slide 15

Slide 15 text

z

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Async/Await Example

Slide 19

Slide 19 text

Async/Await Detailed Example

Slide 20

Slide 20 text

Async/Await Handling Errors

Slide 21

Slide 21 text

Async/Await Handling Errors

Slide 22

Slide 22 text

Async/Await Handling Errors

Slide 23

Slide 23 text

Async/Await Examples

Slide 24

Slide 24 text

Async/Await Examples

Slide 25

Slide 25 text

Async/Await Examples

Slide 26

Slide 26 text

Async/Await Examples

Slide 27

Slide 27 text

Browser Support

Slide 28

Slide 28 text

Who Am I? www.jenniferbland.com @ratracegrad www.youtube.com/c/JenniferBland [email protected] github.com/jenniferbland