diff --git a/Sources/MKDirections+Promise.swift b/Sources/MKDirections+Promise.swift index 04e201b..bf81f3a 100644 --- a/Sources/MKDirections+Promise.swift +++ b/Sources/MKDirections+Promise.swift @@ -17,12 +17,12 @@ extension MKDirections { #if swift(>=4.2) /// Begins calculating the requested route information asynchronously. public func calculate() -> Promise { - return Promise { calculate(completionHandler: $0.resolve) } + return Promise(cancellableTask: MKDirectionsTask(self)) { calculate(completionHandler: $0.resolve) } } /// Begins calculating the requested travel-time information asynchronously. public func calculateETA() -> Promise { - return Promise { calculateETA(completionHandler: $0.resolve) } + return Promise(cancellableTask: MKDirectionsTask(self)) { calculateETA(completionHandler: $0.resolve) } } #else /// Begins calculating the requested route information asynchronously. @@ -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 { + return cancellable(calculate()) + } + + /// Begins calculating the requested travel-time information asynchronously. + public func cancellableCalculateETA() -> CancellablePromise { + return cancellable(calculateETA()) + } +#else /// Begins calculating the requested route information asynchronously. public func cancellableCalculate() -> CancellablePromise { return cancellable(calculate()) @@ -67,4 +78,5 @@ extension MKDirections { public func cancellableCalculateETA() -> CancellablePromise { return cancellable(calculateETA()) } +#endif } diff --git a/Sources/MKMapSnapshotter+Promise.swift b/Sources/MKMapSnapshotter+Promise.swift index 86ebc2e..cffe2ff 100644 --- a/Sources/MKMapSnapshotter+Promise.swift +++ b/Sources/MKMapSnapshotter+Promise.swift @@ -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 { - return Promise { start(completionHandler: $0.resolve) } + return Promise(cancellableTask: MKMapSnapshotterTask(self)) { start(completionHandler: $0.resolve) } } #else /// Starts generating the snapshot using the options set in this object. @@ -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 { + return cancellable(start()) + } +#else /// Starts generating the snapshot using the options set in this object. public func cancellableStart() -> CancellablePromise { return cancellable(start()) } +#endif }