6
Używam BrightFutures i po uruchomieniu następującego kodu, sequence().onComplete
i sequence().onSuccess
jest wywoływana przed zakończeniem instrukcji geoCoderHandler. Czy możesz mi pomóc, aby to działało?Promise.onSuccess natychmiast zadzwonił
self.uploadContentSequence = [Future<Future<Void, NoError>, NoError>]();
for post in posts {
self.uploadContentSequence.append(future(self.preparePostUpload(post)))
}
self.uploadContentSequence.sequence().onComplete { (_) -> Void in
print("onComplete")
}.onSuccess { (_) -> Void in
print("onSuccess")
}.onFailure { (_) -> Void in
print("onFailure")
}
[...]
func preparePostUpload(post: Post) -> Future<Void, NoError> {
let promise = Promise<Void, NoError>()
[...]
let postLocation = CLLocation(latitude: Double(post.lat!), longitude: Double(post.lng!))
let geocoder = CLGeocoder();
let countryCode = NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String
post.country = countryCode
geocoder.reverseGeocodeLocation(postLocation, completionHandler: { (placemarks, locError) -> Void in
[...]
promise.success()
});
return promise.future
}