Now I am migrating from PromiseKit to Concurrency. As I understood, I should replace Promise
and Guarantee
with Task
. However, I cannot find a replacement for Promise<T>.pending()
. Is there something similar in Concurrency?
For instance, I want to use Task
in the code below:
import CoreLocation
import PromiseKit
class A: NSObject {
let locationManager = CLLocationManager()
let promiseAndResolver = Promise<CLLocation>.pending()
func f() {
locationManager.delegate = self
locationManager.requestLocation()
}
}
extension A: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
promiseAndResolver.resolver.fulfill(location)
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
promiseAndResolver.resolver.reject(error)
}
}
class B {
let a = A()
func f() {
a.promiseAndResolver.promise.done {
print($0)
}.cauterize()
a.f()
}
}
let b = B()
b.f()