Last active
May 17, 2018 14:52
-
-
Save eriadam/08592e78acef4366b5a6f0cc4c4f4c28 to your computer and use it in GitHub Desktop.
Async swift with AwaitKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment