Skip to content

Instantly share code, notes, and snippets.

@enomoto
Last active May 10, 2018 01:07
Show Gist options
  • Save enomoto/9fb835e619a23c27b2bbf2b74fb89338 to your computer and use it in GitHub Desktop.
Save enomoto/9fb835e619a23c27b2bbf2b74fb89338 to your computer and use it in GitHub Desktop.
PromiseKit 6 example with Xcode 9.2 and Swift 4.1
import Foundation
import PromiseKit
struct YoRepository {
func fetchDataWithPromise() -> Promise<String> {
return Promise { seal in
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .milliseconds(500)) {
guard true else {
// failure
seal.reject(MyError.unknown)
return
}
// success
seal.fulfill("yo! fulfill called")
}
}
}
}
struct YoUseCase {
func fetchYo() {
firstly {
YoRepository().fetchDataWithPromise()
}.done { result in
print(result)
}.catch { error in
print("some kind of error getting yo! -> \(error)")
}
}
}
enum MyError: Error {
case unknown
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment