I'm using BrightFutures and when I run the following code, sequence().onComplete
and sequence().onSuccess
is called before the geoCoder completionHandler is finished. Can you help me please to get this running?
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
}
As phimage pointed out in this issue: https://github.com/Thomvis/BrightFutures/issues/111 I was wrapping the future with a completed future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With