This repository was archived by the owner on Dec 3, 2022. It is now read-only.
forked from PromiseKit/MapKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMKDirections+Promise.swift
More file actions
59 lines (47 loc) · 1.7 KB
/
MKDirections+Promise.swift
File metadata and controls
59 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import MapKit
#if !PMKCocoaPods
import PMKCancel
import PromiseKit
#endif
/**
To import the `MKDirections` category:
use_frameworks!
pod "PromiseKit/MapKit"
And then in your sources:
import PromiseKit
*/
extension MKDirections {
/// Begins calculating the requested route information asynchronously.
public func calculate() -> Promise<MKDirectionsResponse> {
return Promise { calculate(completionHandler: $0.resolve) }
}
/// Begins calculating the requested travel-time information asynchronously.
public func calculateETA() -> Promise<MKETAResponse> {
return Promise { calculateETA(completionHandler: $0.resolve) }
}
}
//////////////////////////////////////////////////////////// Cancellation
fileprivate class MKDirectionsTask: CancellableTask {
let directions: MKDirections
var cancelAttempted = false
init(_ directions: MKDirections) {
self.directions = directions
}
func cancel() {
directions.cancel()
cancelAttempted = true
}
var isCancelled: Bool {
return cancelAttempted && !directions.isCalculating
}
}
extension MKDirections {
/// Begins calculating the requested route information asynchronously.
public func calculateCC() -> CancellablePromise<MKDirectionsResponse> {
return CancellablePromise(task: MKDirectionsTask(self)) { calculate(completionHandler: $0.resolve) }
}
/// Begins calculating the requested travel-time information asynchronously.
public func calculateETACC() -> CancellablePromise<MKETAResponse> {
return CancellablePromise(task: MKDirectionsTask(self)) { calculateETA(completionHandler: $0.resolve) }
}
}