Spring reactor - trigger method with delay without waiting for the results

Viewed 47

In my spring webflux I want to create a method mainFlow() which returns email address from the getToAddress() method. Each time someone executes the mainFlow() I want it to trigger execution of the method sendEmail() with 5 seconds delay. I don't want to wait for the results of the sendEmail I just want it to be executed aside the mainFlow. How to do it ?

Can I trigger functions on a separate thread or should I create some sort of blocking quqeue and consumer of its to be able to do it ?

fun mainFlow(): Mono<String> {
  return getToAddress()
      .doOnNext{
      // I want the getToAddress() result to be immediately return + I want the sendEmail message to be executed with 5 seconds delay
         sendEmail(it)
      }

}


private fun getToAddress(): Mono<String> {
      ...
    

private fun sendEmail(toAddress: String): Mono<Void> {
      ...
0 Answers
Related