Created
June 18, 2019 12:25
-
-
Save matiasvillaverde/63539d91a2299be4dae8f14a85c3e028 to your computer and use it in GitHub Desktop.
This file contains 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
struct Urn {} | |
struct Track {} | |
// Return sync but is async :O | |
func track(for urn: Urn) -> Future<Track> { | |
let promise = Promise<Track>() | |
let remoteTrack = Track() // Imaginte this is async | |
promise.resolve(with: remoteTrack) | |
return promise | |
} | |
// Client | |
let future = track(for: Urn()) | |
future.then { result in | |
switch result { | |
case let .success(track): | |
print(track) | |
case let .failure(error): | |
print(error.localizedDescription) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment