Advertisement
Guest User

Untitled

a guest
May 31st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // Option 1: Callback Hell
  2. signIn(username: "Foo", password: "Bar") { user in
  3. self.sendWelcomeMailToUser(user) { _ in
  4. self.redirectToThankYouScreen() { _ in
  5. print("All done!")
  6. }
  7. }
  8. }
  9.  
  10. // Option 2: Promises Chained
  11. signIn(username: "Foo", password: "Bar")
  12. .then { user in
  13. return self.sendWelcomeMailToUser(user)
  14. }
  15. .then { _ in
  16. return self.redirectToThankYouScreen()
  17. }
  18. .then { _ in
  19. print("All done!")
  20. }
  21.  
  22. // Option 3: Await Awesomeness
  23. let user = try! await(signIn(username: "Foo", password: "Bar"))
  24. try! await(sendWelcomeMailToUser(user))
  25. try! await(redirectToThankYouScreen())
  26.  
  27. print("All done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement