Combine Future

Let’s say we have 2 business logics and one needs the other ones’ output to process. Here in this case we can get help from Future in Combine:

The business logic functions returns Future, we tie them up with flatMap and then subscribe with sink function. See that we erased the Future type to AnyPublisher using eraseToAnyPublisher to make it more flexible.

Now, the business logics might return error, in that case we can handle it in many ways with combine. One way of handling would be:

Here, failingBusinessLogic function returns failure and when we subscribe to it, we get completion with error.

--

--