Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Option 1: Callback Hell
- signIn(username: "Foo", password: "Bar") { user in
- self.sendWelcomeMailToUser(user) { _ in
- self.redirectToThankYouScreen() { _ in
- print("All done!")
- }
- }
- }
- // Option 2: Promises Chained
- signIn(username: "Foo", password: "Bar")
- .then { user in
- return self.sendWelcomeMailToUser(user)
- }
- .then { _ in
- return self.redirectToThankYouScreen()
- }
- .then { _ in
- print("All done!")
- }
- // Option 3: Await Awesomeness
- let user = try! await(signIn(username: "Foo", password: "Bar"))
- try! await(sendWelcomeMailToUser(user))
- try! await(redirectToThankYouScreen())
- print("All done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement