Promise.onSuccess 立即致电
Promise.onSuccess called immediately
我正在使用 BrightFutures,当我 运行 以下代码时,sequence().onComplete
和 sequence().onSuccess
在 geoCoder completionHandler 完成之前被调用。你能帮我弄到这个 运行ning 吗?
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
}
正如 phimage 在本期中指出的那样:https://github.com/Thomvis/BrightFutures/issues/111 我正在用一个完整的未来包装未来。
我正在使用 BrightFutures,当我 运行 以下代码时,sequence().onComplete
和 sequence().onSuccess
在 geoCoder completionHandler 完成之前被调用。你能帮我弄到这个 运行ning 吗?
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
}
正如 phimage 在本期中指出的那样:https://github.com/Thomvis/BrightFutures/issues/111 我正在用一个完整的未来包装未来。