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