Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Swift Hackr
    @SwiftHackr_twitter
    @mxcl any thoughts on this ^ ?
    Swift Hackr
    @SwiftHackr_twitter
    is this possible to do?
    Max Howell
    @mxcl
    I’m surprise the map trick didn’t work
    Swift Hackr
    @SwiftHackr_twitter
    @mxcl Hm I see, could you try a quick experiment on your end? Maybe I am doing something wrong? Let me know please, thanks
    Swift Hackr
    @SwiftHackr_twitter
    ?
    Ric Santos
    @ricsantos
    .map{ $0 as! Playable } perhaps?
    Swift Hackr
    @SwiftHackr_twitter
    @ricsantos just tried it, doesn't work for me : (
    Ric Santos
    @ricsantos
    how about as! Promise<T> like the error message says?
    Swift Hackr
    @SwiftHackr_twitter
    image.png
    no good
    I feel like this should be documented?
    @ricsantos
    Ric Santos
    @ricsantos
    Can you pls paste some code here that doesn't compile and I can take a look
    Swift Hackr
    @SwiftHackr_twitter
    yeah, I will, thanks
    Rick M
    @JetForMe
    I created an attempt function to retry some operations. One thing I notice is that references to my class's methods when using attempt get a warning from the compiler if I don't use self.. But if I use firstly instead, that doesn't happen. Does anyone know why that is?
    Rick M
    @JetForMe
    Oh! It's because the closure @escaping in attempt, but not in firstly
    Rick M
    @JetForMe
    I'm trying to see how to integrate progress reporting with PromiseKit. I saw the discussions about using something like NSProgress to do this, but it's not entirely clear how. For example, if I'm using PMKAlamofire, how would I show progress for a download?
    Rick M
    @JetForMe
    Oh, I think I see. Alamofire's progress method can be used with something like NSProgress. I guess it's okay that PMK doesn't have its own progress reporting, it just means each thing wrapped in PMK has to have custom progress reporting.
    Jose
    @pepone
     firstly {
                PBSUnknownAsPreservedWithGraphAsync(current: current)
            }.done(on: nil) { iceP_returnValue in
                inS.write { ostr in
                    ostr.write(iceP_returnValue)
                    ostr.writePendingValues()
                }
            }.catch(on: nil) { err in
                inS.exception(err)
            }

    If I had this code and

    func PBSUnknownAsPreservedWithGraphAsync(current: Current) -> Promise<Preserved?> {
            return Promise<Preserved?> { seal in
    
                try current.adapter!.getDispatchQueue().async(flags: .barrier) {
                    let r = PSUnknown()
                    r.pi = 5
                    r.ps = "preserved"
                    r.psu = "unknown"
                    r.graph = PNode()
                    r.graph!.next = PNode()
                    r.graph!.next!.next = PNode()
                    r.graph!.next!.next!.next = r.graph
                    seal.fulfill(r) // Ice marshals r now
                    r.graph!.next!.next!.next = nil // break the cycle
                }
            }
        }

    My assumption is that r.graph!.next!.next!.next = nil // break the cycle will always run after the done block because of done(on: nil) but this doesn't seems to work this way

    isn't done expected to run in the thread that fulfill the promise because of done(on:nil)?
    Max Howell
    @mxcl
    Your assumptions are wrong
    The promise initializer executes its closure immediately
    As per its documentation
    So it depends how you call PBSUnknownAsPreservedWithGraphAsync
    If you call it inside a handler then your desires will occur
    done(on:nil) runs on the same thread as the previous handler
    Not the thread the chain was created
    Running it on the thread the chain was created is impossible with Apple’s frameworks
    Bernard Normier
    @bernardnormier
    To follow-up on Jose's question and give more context. This code snippet is part of the Ice test suite (Ice is a RPC framework, and Ice for Swift beta was released a few days ago). As you can see, Ice uses PromiseKit :-).
    The firstly block is generated code that calls the PBSUnknownAsPreservedWithGraphAsync method (user code). For this code, current.adapter!.getDispatchQueue() retrieves the dispatch queue that executes firstly. The async-with-barrier ensure the done/catch handlers are registered on the pending promise before this promise is fulfilled. And since these are the only handlers, all registered with on: nil, I think the handler will execute in the thread that fulfills the promise. If not, which thread would execute these handlers?
    Also, this code seems to work fine. There was just a bug with the dispatch queues: current.adapter!.getDispatchQueue() did not return the current dispatch queue. Once fixed, all good.
    Max Howell
    @mxcl

    I think the handler will execute in the thread that fulfills the promise

    Yes that is correct

    Yeah I think I was wrong above, quick response without reading properly first
    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