Combine: Is there any operator andThen, which will wait for completion of one future and start another future?

Hi!

I have two futures, A and B.

I would like to call first future and then call another future.
I can't use flatMap, because it waits for values from publisher, but Future may not emit values and just complete.

One possible operator is A.andThen(B) from Rx libraries family.

Hello,

When you have a publisher that may complete without publishing anything, you can use the replaceEmpty operator in order to grab a sentinel value of your choice and have flatMap deal with it. You can even build your own andThen on top of replaceEmpty.

Now:

  • Combine's Future can not complete without publishing any value, so something sounds odd in your question. I guess it is possible to subscribe too late, so I won't dig further.
  • This website is about the Swift language itself, not the usage of Apple SDKs and libraries. You'll be in a better place on https://developer.apple.com/forums/ or http://stackoverflow.com.
Terms of Service

Privacy Policy

Cookie Policy