@@ -17,12 +17,12 @@ extension MKDirections {
1717#if swift(>=4.2)
1818 /// Begins calculating the requested route information asynchronously.
1919 public func calculate( ) -> Promise < Response > {
20- return Promise { calculate ( completionHandler: $0. resolve) }
20+ return Promise < Response > ( cancellableTask : MKDirectionsTask ( self ) ) { calculate ( completionHandler: $0. resolve) }
2121 }
2222
2323 /// Begins calculating the requested travel-time information asynchronously.
2424 public func calculateETA( ) -> Promise < ETAResponse > {
25- return Promise { calculateETA ( completionHandler: $0. resolve) }
25+ return Promise < ETAResponse > ( cancellableTask : MKDirectionsTask ( self ) ) { calculateETA ( completionHandler: $0. resolve) }
2626 }
2727#else
2828 /// Begins calculating the requested route information asynchronously.
@@ -58,6 +58,17 @@ private class MKDirectionsTask: CancellableTask {
5858//////////////////////////////////////////////////////////// Cancellable wrappers
5959
6060extension MKDirections {
61+ #if swift(>=4.2)
62+ /// Begins calculating the requested route information asynchronously.
63+ public func cancellableCalculate( ) -> CancellablePromise < Response > {
64+ return cancellable ( calculate ( ) )
65+ }
66+
67+ /// Begins calculating the requested travel-time information asynchronously.
68+ public func cancellableCalculateETA( ) -> CancellablePromise < ETAResponse > {
69+ return cancellable ( calculateETA ( ) )
70+ }
71+ #else
6172 /// Begins calculating the requested route information asynchronously.
6273 public func cancellableCalculate( ) -> CancellablePromise < MKDirectionsResponse > {
6374 return cancellable ( calculate ( ) )
@@ -67,4 +78,5 @@ extension MKDirections {
6778 public func cancellableCalculateETA( ) -> CancellablePromise < MKETAResponse > {
6879 return cancellable ( calculateETA ( ) )
6980 }
81+ #endif
7082}
0 commit comments