Skip to content

Commit

Permalink
Add an async variant of TKTripFetcher.downloadTrip
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk committed Nov 28, 2023
1 parent d0ba31b commit b32b3ec
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/TripKit/server/TKTripFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum TKTripFetcher {
case serverError(String? = nil)
}

@available(*, renamed: "downloadTrip(_:identifier:into:)")
public static func downloadTrip(_ url: URL, identifier: String? = nil, into context: NSManagedObjectContext, completion: @escaping (Result<Trip, Error>) -> Void) {

let identifier = identifier ?? String(url.absoluteString.hash)
Expand Down Expand Up @@ -60,6 +61,15 @@ public enum TKTripFetcher {

}

public static func downloadTrip(_ url: URL, identifier: String? = nil, into context: NSManagedObjectContext) async throws -> Trip {
return try await withCheckedThrowingContinuation { continuation in
downloadTrip(url, identifier: identifier, into: context) { result in
continuation.resume(with: result)
}
}
}


public static func update(_ trip: Trip, url: URL? = nil, aborter: @escaping ((URL) -> Bool) = { _ in false }, completion: @escaping (Result<(Trip, URL, didUpdate: Bool), Error>) -> Void) {
let url = url ?? trip.updateURLString.flatMap( { URL(string: $0) })
guard let updateURL = url else {
Expand Down

0 comments on commit b32b3ec

Please sign in to comment.