Asynchronous Control Flow Patterns

In the previous post, I covered how to avoid common pitfalls when using Promises. In this post, we’ll look at how Promises and JavaScript’s collection manipulation functions (read map and reduce) can be combined together to implement a few async control flow patterns. Continue reading

Advertisements

JavaScript Promises – Gotchas and Anti Patterns

tl;dr

  • Flatten the Promise chain whenever possible
  • Straighten multiple nested promises with q.all() and q.spread()
  • Don’t break the Promise chain. Make sure that the last promise is returned to the caller.
  • Don’t overuse deferreds. Use them to promisify callback functions. In case a function returns a promise, it’s just better to form a chain with that same promise.

The long version

Continue reading