This guide is for mentors. It outlines how to run the session, what to emphasize, and why we introduce certain terminology.
By the end of this session, trainees should:
- Understand why Promises exist (solving callback hell)
- Consume Promises with
.then()and.catch() - Create Promises with
new Promise() - Use
async/awaitfor cleaner async code - Handle errors with
try/catch - Use
Promise.all()for parallel operations - Fetch data from the Tea Shop API
| Term | Why we introduce it |
|---|---|
| Promise | Core concept for modern async JavaScript. They'll use this everywhere. |
| resolve / reject | Understanding Promise outcomes is essential for proper error handling. |
| then / catch | The foundational API for working with Promises. |
| async / await | Modern syntax they'll use daily. Built on Promises. |
| Promise.all | Essential for performance - parallel operations. |
- Recall Week 2: callback hell example
- "There has to be a better way" - introduce Promises
- Show the transformation: nested callbacks → chained Promises → async/await
Use: Slides (introduction sections)
- Start with consuming, NOT creating Promises
- Use
fetch()- a real function that returns a Promise - Live code: fetch teas from the API
- Explain
.then()and.catch() - Emphasize:
.then()returns a Promise (enables chaining)
Key point: "When you have a Promise, you can call .then() for success and .catch() for failure."
Exercises: Part 1 (exercises 1-4)
- Show chaining: one
.then()after another - The return value becomes the next
.then()'s input - One
.catch()at the end handles all errors - Compare to callback hell: flat vs nested
Key point: "Each .then() returns a new Promise. That's what makes chaining work."
Exercises: Part 2 (exercises 5-6)
- Now show how to CREATE Promises
new Promise((resolve, reject) => { ... })- Convert callback-based code to Promise-based
- Live code: promisify
setTimeout - Live code: promisify
fs.readFile
Key point: "resolve = success, reject = failure. You decide when to call them."
Exercises: Part 3 (exercises 7-9)
- "Promises are great, but there's even cleaner syntax"
asyncmakes a function return a Promiseawaitpauses until Promise resolves- Live code: rewrite
.then()chains with async/await - Error handling with
try/catch
Key point: "async/await is just Promises with nicer syntax. The code looks synchronous but runs asynchronously."
Exercises: Part 4 (exercises 10-13)
- Problem: sequential requests are slow
- Solution: run them in parallel with
Promise.all() - Live code: fetch multiple teas at once
- Show timing difference
Key point: "Promise.all runs operations in parallel. Much faster when requests don't depend on each other."
Exercises: Part 5 (exercises 14-15)
- Recap: Promises → .then/.catch → async/await → Promise.all
- Mention Part 6 (Authentication) as optional stretch for fast learners
- Preview Week 4: "Next week we organize code with Classes"
- Introduce the assignment
The exercises are intentionally numerous - trainees progress at different speeds. Here's how to manage this:
- Let trainees work on Part 1 - observe how far each gets individually
- Solve one exercise in plenum - pick one that weaker trainees struggled with but stronger trainees just finished. This way everyone benefits
- Move on to Part 2 - weaker trainees skip remaining Part 1 exercises (they can revisit later)
- Repeat for each part
Exercises marked with ⭐ are optional stretch goals. If your fastest trainees finish all exercises while others haven't solved the first one, that part needs an additional challenge - let us know, or create a PR with a creative challenging exercise!
trainees often get confused when Promise creation and consumption are mixed. Teach them separately:
- First: "Here's a Promise (from fetch). How do we USE it?"
- Later: "How do we CREATE our own Promises?"
Don't explain async/await until they understand .then/.catch. async/await is sugar on top of Promises - if they don't understand Promises, async/await will be magic they can't debug.
The Tea Shop API makes exercises concrete. trainees see real network delays, real errors, real data. Much more engaging than setTimeout simulations.
- Forgetting
await(getting Promise objects instead of values) - Forgetting to return in
.then()chains - Not handling errors (no
.catch()or try/catch) - Using
awaitoutside anasyncfunction
- Slides - Reveal.js presentation
- Exercises - In-session exercises
- Assignment - Take-home work
- Tea Shop API - Live API for exercises