promisekit

Collect array of successful promises

雨燕双飞 提交于 2020-01-06 14:59:28
问题 I'm using PromiseKit 3.0 in Swift and I have an array of promises [Promise<Int>] . I want to gather up all the promises that succeed into a single promise. Promise<[Int]> . Both when and join reject if even one contained promise rejects. According to the docs, I'm supposed to be able to use join and the error will contain an array of the fulfilled values, but in Swift the error contains all the promises that were passed in, not the fulfilled values. Any help would be appreciated. 回答1: I see

Swift - multiple Chain http request with loop

半世苍凉 提交于 2020-01-02 16:18:20
问题 Since 2 days it feels that I'm searching the whole web to solve my problem with multiple http requests. So my workflow looks like this: Upload a image to a server Response = XML Format with a Task ID GET request to the server with the Task ID to check the status of this task. Response = XML Format where the status could be "Completed", "In Progress", "Queued" If Status != "Completed" - retry step 2 If Status == "Completed" - go to step 3 Download the result from the resultUrl My last try was

How to refactor swift callback to promise with PromiseKit

岁酱吖の 提交于 2019-12-12 02:27:53
问题 I am attempting my first foray into swift promises with PromiseKit, after some experience with doing them with bluebird in node. My original service function for authentication with a callback looks like this: private func requestNewToken(email : String, password: String, completion: (success: Bool, token: String?, userId : String?, message: String? ) -> Void) { Alamofire.request(Router.Authenticate(email, password).URLRequest) .responseJSON { request, response, result in switch result { case

Error handler not called for promise

做~自己de王妃 提交于 2019-12-11 12:07:31
问题 I have a service, which fails when I enter bad login credentials. However, my Promise error handler does not get called. I don't seem to grasp what's wrong with my code so that the error callback is never reached. Service func loadRepositories() -> Promise<[Repository]>{ return Promise { fullfill, reject in manager.request(Method.GET, baseURL + "/api/1.0/user/repositories") .authenticate(user: username, password: password) .responseArray { (response: Response<[Repository], NSError>) in switch

Cannot convert return expression of type Promise (_,_) -> DataRequest to return type Promise<DataResponse,AnyObject>>

旧时模样 提交于 2019-12-11 05:57:33
问题 Cannot convert return expression of type Promise ( , ) -> DataRequest to return type Promise> my function is func postJson(_ url: String, parameters: [String: String]) -> Promise<DataResponse<AnyObject>> { var request = URLRequest(url: URL(string: url)!) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.httpBody = try! JSONSerialization.data(withJSONObject: parameters) return Promise { fulfill, reject in manager.request(request)

How to set up when(fulfilled:) in PromiseKit?

萝らか妹 提交于 2019-12-11 00:27:41
问题 I have a function set up to return a Promise<PFObject> . I would like to use this function in PromiseKit's when(fulfilled:) functionality, but whenever I try to do so, I get an error. Here is the function which returns the Promise<PFObject> : func Query() -> Promise<PFObject>{ return Promise{ fulfill, reject in let linkQueryy = PFUser.query() linkQueryy?.findObjectsInBackground(block: { (objectss, error) in if let objects = objectss{ for object in objects{ fulfill(object) } } }) } } As you

Ambiguous use of recover error while using PromiseKit

房东的猫 提交于 2019-12-10 17:57:03
问题 Running into a strange error when using recover while handling errors that can be thrown while executing a promise. Chaining .recover with .then results in compilation if there is more than one statement in recover block. Having single statement in recover block works and having recover alone (promise.recover{} without then works) Attaching screenshots of single statement recover (which works) and multiple statement recover (which throws a compilation error with the message: Ambiguous use of

Returning void in PromiseKit 6

左心房为你撑大大i 提交于 2019-12-09 18:16:38
问题 This is what I had working with PromiseKit 4.5 api.getUserFirstName().then { name -> Void in print(name) } getUserFirstName() returns a Promsise<String> . I updated to PromiseKit 6 and this now throws an error: Cannot convert value of type '(_) -> Void' to expected argument type '(_) -> _' This error message makes little sense to me. How do I fix this? EDIT: So this seems to fix it, but I have little understanding as to what's happening with this: api.getUserFirstName().compactMap { name in

Swift Alamofire + Promise catching

馋奶兔 提交于 2019-12-07 12:27:16
问题 Folks, The following works except for the catch, xcode errors out with expected member name following '.' Is this the proper way to promisify with PromiseKit? All suggestions welcome! Thanks! @IBAction func loginButtonTapped(sender: AnyObject) { let email = userEmail.text! let password = userPassword.text! func onSuccess(success:Bool, message:String, token: String) -> Promise<Void> { if success { NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isUserLoggedIn") NSUserDefaults

Swift - multiple Chain http request with loop

霸气de小男生 提交于 2019-12-06 09:32:01
Since 2 days it feels that I'm searching the whole web to solve my problem with multiple http requests. So my workflow looks like this: Upload a image to a server Response = XML Format with a Task ID GET request to the server with the Task ID to check the status of this task. Response = XML Format where the status could be "Completed", "In Progress", "Queued" If Status != "Completed" - retry step 2 If Status == "Completed" - go to step 3 Download the result from the resultUrl My last try was to use PromiseKit to chain the requests in a clean way like described in this post: Chain multiple