Created
May 31, 2017 20:41
-
-
Save eriadam/402a84aad956056798109530637eb183 to your computer and use it in GitHub Desktop.
Do Stuff Async Example
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
do { | |
// Closure | |
try self.doStuff(string: "Some string") { result in | |
print(result) | |
} | |
// Promise | |
let promise = try self | |
.doStuff(string: "Some other string") | |
promise.then { result -> Void in | |
print(result) | |
} | |
// Await | |
async { | |
let result = await(self.doStuff(string: "Yet another string")) | |
print(result) | |
} | |
} catch { | |
print(error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment