More Related Content


Promises And Chaining In AngularJS - Into Callback Hell And Back Again

  1. Promises and chaining Into callback hell … back again
  2. About Hans @otype
  3. Intro: sync, async, callbacks
  4. Humans are multi-threaded!
  5. Javascript is single-threaded & synchronous. Browsers provide asynchrony*.
  6. finish start a() b() c() a() b() c()
  7. finish start a() b() c() a() b() c() b() a() c() c() b() a() c(),a() b()…
  8. sync async
  9. Why async?
  10. Synchronous flow, here? Bad idea!
  11. “Callbacks to the rescue!”
  12. “Call me back!”
  13. Use a callback! Way better!
  14. Got it!
  15. a() b() c() d() e() f() Callbacks in order?
  16. “Pyramid of doom!”
  17. “I am NOT going to debug that!”
  18. “Free ticket into callback hell!”
  19. Core: Promises to the rescue
  20. “I hereby give you a promise that I will answer your question some time in the future … but not right now!” My definition of a promise
  21. Promise fulfilled rejected pending settled
  22. Still experimental kriskowal/q cujojs/when tildeio/rsvp.js WinJS.Promise
  23. $q.defer()
  24. .then()
  25. .resolve() .reject()
  26. .then() in .then() in .then() …
  27. “I’ve seen that *$#%$* before …”
  28. Chaining
  29. “Wicked, Hans!”
  30. “And what about collecting results from multiple promises?”
  31. Combined results $q.all()
  32. “OK! Enough theory!”
  33. Get fancy: Demo Time!
  34. Outro: Questions?
  35.$q Reference/Global_Objects/Promise
  36. “Thank you! Over & out!”