Giter Site home page Giter Site logo

Comments (6)

heckj avatar heckj commented on May 27, 2024

Hi Marcos -

Combine doesn't quite have the same "chaining promises" structure of the then operator from those systems, but in some cases it can act similarly. I find it awkward to do the more equiv of chaining promises (or one-shot async calls), but you can do it with Combine, using a combination of Future and either flatMap or map & switchToLatest.

I have some of this exposed as a pattern in the work here, specifically the pattern Sequencing operations with Combine.

If you want to do some of the fancy "do these things in parallel and then wait for all to complete" kind of coordination, then zip can come in immensely useful - as it does exactly what you describe - waits for multiple upstream publishers to all be complete before producing a single, unified response to downstream subscribers.

from swiftui-notes.

dehesa avatar dehesa commented on May 27, 2024

Thank you for taking the time. I did see that example, but you are actually chaining on the value and not in the completion. Which wouldn't work for publishers that just complete without sending values (for example).

In any case, I do have my answer. Thank you.

FYI, reading your SwiftUI-notes on the iPad (Safari to be exact) is maddening since every time I jump to another application (e.g. to take notes) the scroll position randomly changes.

from swiftui-notes.

heckj avatar heckj commented on May 27, 2024

thanks for the heads up with safari - i’ll see what i can do to help resolve that.

from swiftui-notes.

heckj avatar heckj commented on May 27, 2024

your absolutely correct about triggering on the value vs completion itself. you might be interested to look at the newer ObservableObjectPublisher ( https://heckj.github.io/swiftui-notes/#reference-observableobjectpublisher ) which has a short of shim/workaround to this specific concept - it triggers with an output of ObservableObject.Output, which is type cast to Void. in the end it means you can get a sink to trigger, but it has no real info passed through to it - just that it happened.

Probably not what you want to use if you’re looking for the moral equiv of a complex promise chain, but interesting detail none the less.

from swiftui-notes.

dehesa avatar dehesa commented on May 27, 2024

It is interesting indeed, thank you.

I think I will go the custom publisher route, though. More like an "educational" experience than anything else. The 3 articles of Matt Gallagher explaining the shadow chain of subscriptions gave me an interesting understanding on Combine's internal usage that I am itching to apply ;)

from swiftui-notes.

dehesa avatar dehesa commented on May 27, 2024

Hi @heckj,

I just wanted to follow up on this question I opened some weeks ago and mention that I ended up rolling my own then operator along with some other publishers/subscribers. Maybe you find them interesting or can give me feedback. You can find my them in this Github repo with a shoutout to your site ;)

Keep up the good work!

from swiftui-notes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.