0

I am looking a way to delay invoke of an Completable function after first Completable is success and all logic is finished.

fun invokeSomeLogic(): Completable {
  return firstCompletable() ----> lets assume is success
  .concatWith(secondCompletable()) ---> lets assume is success
  .concatWith(thirdCompletable()) // THIS IS THE FUNCTION I WANT TO DELAY
  .onErrorResumeNext {...}

}

I want to delay the third for 2 sec after the second one is finished with success. When I was debugging and set some breakpoints on third function it seems that third fun is invoked regardless of second fun. Is this a normal behaviour of concatWith? Appreciate any help!

DM developing
  • 423
  • 5
  • 15
  • How is the `thirdCompletable` implemented? Also methods are invoked because you `()` is an indication of method invocation. You could have just listed thirdCompletable() without any Rx and it would still get invoked. – akarnokd Jul 14 '22 at 07:22
  • Third one returns Completable, it is like: return Completable.fromObservable(...) – DM developing Jul 14 '22 at 07:29
  • Interesting, what I tried now is Completable.deffer{third fun} and it works as intended. Is this function triggered even if error occurs on second fun? Thanks! It seems there is some race condition in codebase so this helped to fix a bug. – DM developing Jul 14 '22 at 07:31
  • 1
    If you are using `concatWith`, then `defer` won't run if the preceding completable failed. – akarnokd Jul 14 '22 at 07:57
  • What if we use andThen(Completable.deffer{third fun} )? – DM developing Jul 14 '22 at 08:49
  • The same. Please check out the javadoc of the operators. – akarnokd Jul 14 '22 at 09:44

0 Answers0