2

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> {
      ...
Clyde Barrow
  • 1,924
  • 8
  • 30
  • 60
  • 3
    See here: https://stackoverflow.com/questions/57566465/fire-and-forget-with-reactor - sounds like you probably want a "fire and forget" type which you can get by subscribing to the inner mono in `doOnNext()`. – Michael Berry Mar 10 '21 at 15:21

0 Answers0