微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift – Promise.onSuccess立即调用

我正在使用 BrightFutures,当我运行以下代码时,在geoCoder completionHandler完成之前调用sequence().onComplete和sequence().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
}

解决方法

正如phimage在本期杂志中所指出的那样: https://github.com/Thomvis/BrightFutures/issues/111我将在未来完成未来.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐