Promise.onSuccess立即调用

Ale*_*olz 6 future promise swift

我使用BrightFutures,当我运行下面的代码,sequence().onComplete以及sequence().onSuccess地理编码器completionHandler完成之前被调用.你能帮助我吗?

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
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*olz 1

正如 phimage 在本期中指出的:https://github.com/Thomvis/BrightFutures/issues/111我正在用一个完整的未来来包裹未来。