Coroutine Reactor and Mono<Void>

Hello, I’ve been playing with coroutines and reactor and I’ve run across one problem. I am trying do delete record from mongodb collection with reactivemongorepository and it return Mono. Which await method should I use to wait for the execution in non blocking way inside GlobalScope.mono{} coroutine?

Hi @lubospecho,
you can use awaitSingle() for your Mono<Void?> (you have to expect a null).

Hi, the reason I asked was because neither awaitSingle nor awaitFirst did not work. Exception was thrown that ‘No value received via onNext for awaitSingle’

However, after I posted the question, I have realized what you have confirmed, that mono Mono will actualy return null, so I have tried awaitFirstOrNull() and it works.

Mono<Void> should be used for Publisher that just completes without any value.

https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html

1 Like