2 Replies
      Latest reply on Jul 12, 2019 4:55 AM by Claude31
      anthroDevChris Level 1 Level 1 (0 points)

        Combine sounds like a great framework, and is finally an excuse to dig into reactive programming.  I am finding the documentation a bit spare though around the concept of promise chaining.

         

        I am hoping to find a good example of promise chaining for combining two serial asynchronous functions -- that is, use the result of one to populate the second. Here's something I was working with as a potential use case:

        • given a UIViewController with a MKMapView
        • user pans the map, and I can store the region when mapView:regionDidChangeAnimated is called in a @published var (e.g. theRegion)
        • create a pipeline that takes theRegion and then does the following:
          -- does an asynchronous function to find all PoIs in the region
          -- does another asynchronous function to find distance for each PoI to the center of the map
          -- finally updates UI by highlighting closest PoI

         

        I am beginning to grok Futures in general, but have not done enough to fully understand it. For a similar idea I have used a lot of OperationQueues and state management and it's a mess... hope this can help simplify that in the end.

         

        A bonus would be showing how to execute the async functions off the main thread.