Skip to content

Instantly share code, notes, and snippets.

@kpuputti
Created September 29, 2015 11:53
Show Gist options
  • Save kpuputti/dce3801db1b5846c6182 to your computer and use it in GitHub Desktop.
Save kpuputti/dce3801db1b5846c6182 to your computer and use it in GitHub Desktop.
Promise patterns

Promise patterns in large JavaScript applications

  • understand the abstraction
    • understand then (fmap/monadic bind)
  • know the difference of deferred and promise
  • be sure not to swallow errors
    • either return or end chain
    • error in success handler ending the chain
  • resolve with a single value (jQuery...)
  • standard error object for rejecting
  • avoid async if not really needed
  • always be fully async
    • add example
  • promises compose nicely, use this to your advantage
    • write generic helpers
    • _.chain() <-> whenAllPromises
    • PromiseQueue
    • splitting tasks, sync duality with return statements
  • parallellize all the IO you can
  • be careful with imperative style and early returns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment