

774: Promise Flow Control, Concurrency, Libraries, TypeScript and Deferreds - Part 3
9 snips May 27, 2024
Scott and Wes wrap up their JavaScript Promises series by diving into advanced concepts like deferred promises and flow control. They explore fetching data from APIs and the importance of concurrency using libraries such as p-map and p-limit. The conversation showcases practical tips for managing asynchronous tasks, including throttling and queuing techniques. They also discuss integrating TypeScript to enhance promise handling, emphasizing how this shift improves code efficiency and reliability in web development.
AI Snips
Chapters
Transcript
Episode notes
Deferred Promises with Resolvers
- Use
Promise.withResolvers()
to access resolve/reject methods outside the promise body. - This avoids creating external variables and simplifies stream handling.
Why Fetch Uses Two Promises
- Fetch uses two promises because servers send headers first, then the body.
- This lets you check response codes before processing the full data payload.
Flow Control with For Loops
- Control promise flow with for...of loops for sequential execution.
- Await inside the loop to pause for each promise's resolution.