6
我使用BrightFutures,當我運行以下代碼時,在geoCoder completionHandler完成之前調用sequence().onComplete
和sequence().onSuccess
。你能幫我解決這個問題嗎?Promise.onSuccess立即致電
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
}