Skip to content

Commit

Permalink
'Cancel' for PromiseKit -- update MapKit cancellable code for Swift 4…
Browse files Browse the repository at this point in the history
….2 and Xcode 10
  • Loading branch information
dougzilla32 committed Sep 7, 2018
1 parent deaf9d7 commit d502999
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 14 additions & 2 deletions Sources/MKDirections+Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ extension MKDirections {
#if swift(>=4.2)
/// Begins calculating the requested route information asynchronously.
public func calculate() -> Promise<Response> {
return Promise { calculate(completionHandler: $0.resolve) }
return Promise<Response>(cancellableTask: MKDirectionsTask(self)) { calculate(completionHandler: $0.resolve) }
}

/// Begins calculating the requested travel-time information asynchronously.
public func calculateETA() -> Promise<ETAResponse> {
return Promise { calculateETA(completionHandler: $0.resolve) }
return Promise<ETAResponse>(cancellableTask: MKDirectionsTask(self)) { calculateETA(completionHandler: $0.resolve) }
}
#else
/// Begins calculating the requested route information asynchronously.
Expand Down Expand Up @@ -58,6 +58,17 @@ private class MKDirectionsTask: CancellableTask {
//////////////////////////////////////////////////////////// Cancellable wrappers

extension MKDirections {
#if swift(>=4.2)
/// Begins calculating the requested route information asynchronously.
public func cancellableCalculate() -> CancellablePromise<Response> {
return cancellable(calculate())
}

/// Begins calculating the requested travel-time information asynchronously.
public func cancellableCalculateETA() -> CancellablePromise<ETAResponse> {
return cancellable(calculateETA())
}
#else
/// Begins calculating the requested route information asynchronously.
public func cancellableCalculate() -> CancellablePromise<MKDirectionsResponse> {
return cancellable(calculate())
Expand All @@ -67,4 +78,5 @@ extension MKDirections {
public func cancellableCalculateETA() -> CancellablePromise<MKETAResponse> {
return cancellable(calculateETA())
}
#endif
}
9 changes: 8 additions & 1 deletion Sources/MKMapSnapshotter+Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension MKMapSnapshotter {
#if swift(>=4.2)
/// Starts generating the snapshot using the options set in this object.
public func start() -> Promise<Snapshot> {
return Promise { start(completionHandler: $0.resolve) }
return Promise<Snapshot>(cancellableTask: MKMapSnapshotterTask(self)) { start(completionHandler: $0.resolve) }
}
#else
/// Starts generating the snapshot using the options set in this object.
Expand Down Expand Up @@ -48,8 +48,15 @@ private class MKMapSnapshotterTask: CancellableTask {
//////////////////////////////////////////////////////////// Cancellable wrapper

extension MKMapSnapshotter {
#if swift(>=4.2)
/// Starts generating the snapshot using the options set in this object.
public func cancellableStart() -> CancellablePromise<Snapshot> {
return cancellable(start())
}
#else
/// Starts generating the snapshot using the options set in this object.
public func cancellableStart() -> CancellablePromise<MKMapSnapshot> {
return cancellable(start())
}
#endif
}

0 comments on commit d502999

Please sign in to comment.