我用 Promise<T> 返回类型包装了我的 2 个 API 请求:
func registerWithEmail(email: String, firstName: String, lastName: String, password: String, subscribe: Bool) -> Promise<Bool>
func requestAccessTokenWithEmail(username: String, password: String) -> Promise<String>
单独使用它们可以正常工作:
firstly {
client.registerWithEmail("foo@gmail.com", firstName: "john", lastName: "smith", password: "password", subscribe: false)
}.then { success -> Void in
completion(success: success)
}.catch { error -> Void in
println(error.localizedDescription)
}
和:
firstly {
client.requestAccessTokenWithEmail("foo@gmail.com", password: "password")
}.then { accessToken -> Void in
println(accessToken)
completion(success: true)
}.catch { error -> Void in
println(error.localizedDescription)
}
then
但是,当我链接它们时,永远不会填充第二个调用的令牌参数:
firstly {
client.registerWithEmail(username, firstName: "a", lastName: "b", password: password, subscribe: false).then { success -> Void in
return client.requestAccessTokenWithEmail(username, password: password)
}.then { accessToken -> Void in
println(accessToken)
completion(success: true)
}
}
如果我打破这个闭包,我无法查看accessToken
参数,只能查看外部completion
闭包。requestAccessTokenWithEmail
但是,如果我在函数内部中断,accessToken
则在调用fulfill
.
我对 PromiseKit 很陌生,所以如果我在做一些愚蠢的事情,请告诉我。
我正在使用 PromiseKit 2.0、Swift 1.2、Xcode 6.4