Performing side step operation in reactive programming

26 Views Asked by At
  fun test1(): Mono<ResponseFromTest2> {
        return test2()
            .flatMap { responseFromTest2 ->
               // do some operation
               Mono.just(responseFromTest2) 
             }
            .doOnNext {
                publishMetrics()
            }
    }

I am trying to find an operator where in I can perform a side-step operation. I was considering using the doOnNext operator. One issue here is if publishMetrics() function throws any exception, the Mono emitted from the flatMap won't be propagated but the error will be propagated instead. This seems like an unnecessary work from a side-step operation. One way is to handle the exception through try-catch block. But I wanted to know if there is any such operator which would handle the exception implicitly without us writing a try-catch block or any onErrorResume. To simplify with respect to this example: Is there any operator that can perform a side-step operation, if any exception thrown by the side-step operation won't be propagated downstream and the initial Mono emitted from the flatMap will instead be passed downstream.

0

There are 0 best solutions below