Syntax - Tasty Web Development Treats

771: Promises: Error Handling, Aborts, and Helper Methods - Part 2

May 20, 2024
Discover essential techniques for mastering promises in this deep dive into error handling and abort methods. Learn how to effectively cancel promises and improve performance using abort signals. Get insights into the differences between Promise.all and Promise.allSettled, and explore the nuances of Promise.any and Promise.race. The discussion also emphasizes error handling strategies with practical examples, along with advanced techniques for implementing timeouts and static methods like Promise.reject and Promise.resolve. Perfect for improving your async programming skills!
Ask episode
AI Snips
Chapters
Transcript
Episode notes
ADVICE

Canceling Promises with AbortController

  • Use AbortController signals to cancel fetch requests.
  • This helps manage multiple requests and avoid out-of-order responses, especially useful with type-ahead searches.
INSIGHT

Promise.all vs. Promise.allSettled

  • Promise.all resolves when all promises resolve, but rejects if any single promise rejects.
  • Promise.allSettled resolves with an array of all results, regardless of individual promise outcomes.
ADVICE

Using promise.finally

  • Use promise.finally to execute code after a promise resolves or rejects.
  • This is handy for cleanup tasks like turning off loaders, regardless of the outcome.
Get the Snipd Podcast app to discover more snips from this episode
Get the app