Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Max Howell
    @mxcl
    the done(on: nil) will execute on the queue the seal.fulfill is in
    Alexander Edunov
    @AlexEdunov
    Hey, guys! What are your plans for PromiseKit 7? Looking forward to use cancellable promises!
    Štembera Michal
    @stemberamichal
    Hello, I am currently using PromiseKit in version 4.5.2 in Swift 4 project and I would like to use DispatchQueue.promise (the one that returns promise). But that is unavailable due to compiler bug. With which version does this get resolved? I have quite a few dependencies and also aware that PromiseKit syntax has changed a little bit in version 5, so I am not sure if I am capable of migrating to version 5.
    Štembera Michal
    @stemberamichal
    I am sorry for bothering, I think I have already figured out. I'll use DispatchQueue.promise that returns Void and chain the rest behind it :)
    Max Howell
    @mxcl
    I would upgrade to PMK 6, 5 is deprecated as our documentation says
    4 is not getting much attention, though I don't think there's any bugs
    @AlexEdunov I haven't tested 7 in any real code yet, which is my main concern, I dunno if anyone has actually tried to use it in practice
    Like, go ahead, use it, tell us how it is, someone should
    Štembera Michal
    @stemberamichal
    Thank you @mxcl I'll upgrade to 6.
    thirty7four2
    @thirty7four2
    I'm trying to call a promise that polls for data, and if it hasn't got the data in a certain amount of time, then I just want to take a default value, but can't get this to compile.
    ```let fetch: Promise<String> = self.pollingTask()
    let timeout: Promise<String> = firstly { after(seconds: 10).then { return .value("some default")}}
        return race(when(resolved: fetch, timeout)).then { result -> Promise<String> in
            return .value(result) // Member 'value' in 'Promise<String>' produces result of type 'Promise<T>', but context expects 'Promise<String>'```
    thirty7four2
    @thirty7four2
    Also, it is waiting the full 10 seconds for the timeout promise to complete, even if I set the other promise to return a value immediately.
    Max Howell
    @mxcl
    let fetch = self.pollingTask()
    let timeout = after(seconds: 10).map{ "some default" }
    return race(fetch, timeout)
    Not sure why you embedded a when that (as the docs say) waits for all promises you provide it. So obviously it would wait 10 seconds whatever was happening. Recommend reading docs.
    thirty7four2
    @thirty7four2
    Thanks! that worked
    It has race(when(fulfilled: fetches).asVoid(), timeout).then { //… }
    Now, I noticed the when is around the array of fetches
    Anthony Maina
    @mainaaw
    Hey @mxcl, I had a quick question regarding promise initialization that I feel should be quick fix but I can't get it right. I need to initialize a Promise and then use it in a thunk elsewhere. Something like:
    func foo() -> (Thunk, Promise) {
       let promise = Promise()
       let thunk = Thunk { ... promise.fulfill() ... }
       return (thunk, promise)
    }
    let (thunk, promise) = foo()
    dispatch(thunk)
    promise.done { ... }
    My issue is just how do I initialize a promise that returns [String :Any]
    Gabriel Montague
    @montaguegabe
    Hi all, how can I use PromiseKit 7 in my project? Is there an option to do so through CocoaPods?
    Štembera Michal
    @stemberamichal

    Hello @montaguegabe , I hope It won't mind if I answer as this is a common CocoaPods question mostly.

    PromiseKit 7 Alpha
    We are testing PromiseKit 7 alpha, it is Swift 5 only. It is tagged and thus importable in all package managers.

    According to CocoaPods for bleeding edge uses you can specify url and tag:

    pod 'PromiseKit', :git => 'https://github.com/mxcl/PromiseKit.git', :tag => '7.0.0-alpha3'
    Štembera Michal
    @stemberamichal

    Hi @mainaaw what are you probably looking for is Promise<T>.pending()

    In your case you can use it as follows (PromiseKit 4 unfortunately - adjust in newer versions):

    typealias Thunk = () -> Void
    func foo() -> (Thunk, Promise) {
        let pending = Promise<[String: Any]>.pending()
        return  (
            { ... pending.fulfill() ... },
            pending.promise
        )
    }
    Gabriel Montague
    @montaguegabe
    @stemberamichal thank you very much! Sorry to bother you with such a simple question; I thought in here I had read someone say you had to clone the repo
    Štembera Michal
    @stemberamichal
    @montaguegabe Don't worry, I just wondered by in search for answer to my own question. Glad I could help :)
    Gary Hooper
    @garyhooper
    Trying to test PromiseKit 7, I get an error with cocoapods: "Unable to find a specification for 'PromiseKit'." What is the most straightforward way to install it? Can you create a cocoapods spec file for v7?
    Gabriel Montague
    @montaguegabe
    I couldn't find any cocoapods spec file either. But you can get it working by cloning the repo, building for "Generic iOS Device", copying the framework into your project, then making sure it also in the "Embed Frameworks" section
    Gabriel Montague
    @montaguegabe
    Any pointers on how to get this working with CoreLocation extension would be greatly appreciated. – Or are all the extensions Objective C and thus now unusable?
    Tony1120
    @Tony1120
    hi
    Does anyone know how to get the "didsentbodydata" delegation method work with the promise kit? I have datatask in my promise chain but the delegation method is never called
    Nitish Sachar
    @uioporqwerty
    For PromiseKit 6, how do you take multiple arrays of type [Promise<Int>] and resolve them all at once? when(fulfilled: promiseArr1, promiseArr2...) throws this error Global function 'when(fulfilled:_:)' requires that '[Promise<Int>]' conform to 'Thenable'
    Max Howell
    @mxcl
    @uioporqwerty when(fulfilled: promiseArr1 + promiseArr2)
    @Tony1120 impossible to help with so little context
    qazi1002
    @qazi1002
    Hi anyone here to help?
    Max Howell
    @mxcl
    @qazi1002 hi
    Harrison Friia
    @harrisonfriia

    Hello - I’m writing a wrapper for our base API call, which returns a custom error type APIServiceError.
    The wrapper looks like this:

    func send<T: Decodable>(request: Request) -> Promise<T> {
            return Promise { seal in
                let completion: (Swift.Result<T, APIServiceError>) -> Void = { result in
                    switch result {
                    case .success(let data):
                        seal.fulfill(data)
                    case .failure(let error):
                        seal.reject(error)
                    }
                }
                self.send(request: request, completion: completion)
            }
        }

    When I call that wrapper, is it possible for the catch block to return my custom error type rather than Error?

    func foo(request: Request) {
            self.apiClient.send(request: request).done { (result: Session) in
    
            }.catch { (error) in
                // error here is Error, not APIServiceError
            }
        }
    Ric Santos
    @ricsantos
    is APIServiceError a Swift Error?
    if so, you can do this inside the catch:
                switch error {
                case ModelError.objectNotFound:
                        // handle your error case
                default:
                      // handle other errors
                }
    Harrison Friia
    @harrisonfriia
    Yep, specifically a LocalizedError. I'm wondering if the type can be inferred directly so I don't have to do any casting
    Ric Santos
    @ricsantos
    Well it could be an Error, or your APIServiceError, so you will need to check its type...
    Harrison Friia
    @harrisonfriia
    Right, but I want to know if there's a way to get catch to give me an APIServiceError specifically
    Ric Santos
    @ricsantos
    Well you can do that I suppose, when you call seal.reject() only do that if its an APIServiceError. What would you do if it a different error though?
    Ian Manor
    @imvm
    Is there any way to get the results of when(fulfilled:) promises in a map? I want to write something like this:
    func getPromise() -> Promise<SomeObject> {
        when(fulfilled: promiseA, promiseB).map { resultA, resultB in
            doSomething(resultA, resultB)
        }
    }
    
    func doSomething(a: ObjectA, b: ObjectB) { return SomeObject(a, b) }
    I want to avoid having to do this:
    funs getPromise() -> Promise<SomeObject> {
        let promiseA = ...
        let promiseB = ...
    
        when(fulfilled: promiseA, promiseB).map { _ in
            doSomething(promiseA.value!, promiseB.value!)
        }
    }
    
    func doSomething(a: ObjectA, b: ObjectB) { return SomeObject(a, b) }
    Aaron Hilton
    @otri
    I'm having trouble getting the swift compiler to figure this out:
                firstly {
                    return Promise { seal in
                        Purchases.shared.purchaserInfo() { purchaserInfo, error in
                            seal.resolve(purchaserInfo, error)
                        }
                    }
                }
    Gives me a couple errors
    Generic parameter 'T' could not be inferred
    Generic parameter 'U' could not be inferred
    Aaron Hilton
    @otri
    So I'm sad to say, I've switched frameworks.
    I've been battling with PromiseKit's swift compiler errors (and swift's poor error messages) a lot on this project, so ultimately I have switched to Google's Promises framework. So this was a bit surprising, because PromiseKit seems really solid otherwise. I assumed it was my misunderstanding the nature of the framework. However, these ambiguity errors went on and on, forcing re-write and restructuring to work around it, and so on, these issues just wouldn't go away.
    A fundamental thing about PromiseKit that ended up becoming a bit detrimental was how "magic" the type bindings and semantics worked. Without explicit control over typed promises, ambiguity edge cases would crop up. Whereas the Google Promises framework allows a more explicit type binding, and a clearer promise chaining.
    I appreciate the ton of work that went into making an otherwise elegant Promise framework. Just quirks of the swift compiler ruined the party I guess.
    Vinod Reddy
    @vinnuzmobile
    Hello all, Could someone please share me any article about unit testing for using promisekit. Thank you.