@@ -17,12 +17,12 @@ extension MKDirections {
17
17
#if swift(>=4.2)
18
18
/// Begins calculating the requested route information asynchronously.
19
19
public func calculate( ) -> Promise < Response > {
20
- return Promise { calculate ( completionHandler: $0. resolve) }
20
+ return Promise < Response > ( cancellableTask : MKDirectionsTask ( self ) ) { calculate ( completionHandler: $0. resolve) }
21
21
}
22
22
23
23
/// Begins calculating the requested travel-time information asynchronously.
24
24
public func calculateETA( ) -> Promise < ETAResponse > {
25
- return Promise { calculateETA ( completionHandler: $0. resolve) }
25
+ return Promise < ETAResponse > ( cancellableTask : MKDirectionsTask ( self ) ) { calculateETA ( completionHandler: $0. resolve) }
26
26
}
27
27
#else
28
28
/// Begins calculating the requested route information asynchronously.
@@ -58,6 +58,17 @@ private class MKDirectionsTask: CancellableTask {
58
58
//////////////////////////////////////////////////////////// Cancellable wrappers
59
59
60
60
extension 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
61
72
/// Begins calculating the requested route information asynchronously.
62
73
public func cancellableCalculate( ) -> CancellablePromise < MKDirectionsResponse > {
63
74
return cancellable ( calculate ( ) )
@@ -67,4 +78,5 @@ extension MKDirections {
67
78
public func cancellableCalculateETA( ) -> CancellablePromise < MKETAResponse > {
68
79
return cancellable ( calculateETA ( ) )
69
80
}
81
+ #endif
70
82
}
0 commit comments