Skip to content

Instantly share code, notes, and snippets.

@matiasvillaverde
Created June 18, 2019 12:25
Show Gist options
  • Save matiasvillaverde/63539d91a2299be4dae8f14a85c3e028 to your computer and use it in GitHub Desktop.
Save matiasvillaverde/63539d91a2299be4dae8f14a85c3e028 to your computer and use it in GitHub Desktop.
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