I have a project with Spring WebFlux and normally we use Kotlin coroutines and don't see many Mono or Flux around. However, from time to time the need arises to integrate with the framework, like implement a custom ReactiveAuthorizationManager where only Project Reactor is known. I implemented such a method but it is very complex, unreadable, nobody understands it (arguably, WebFlux might not be the right choice for this team), and I won't understand it at first glance in a few days either, and it is really awful to step through while debugging. So I had the idea to do something like:
fun someFunction(fooMono: Mono<Foo>): Mono<Bar> {
return mono {
val foo = fooMono.awaitSingleOrNull()
// do stuff
Bar(...)
}
}
which uses Reactor coroutines integration. The code (do stuff above) is then much (in my opinion) easier to understand and can actually be debugged.
Basically it converts a Mono to a coroutine and then back again. Is this a good idea? Is there a big performance penalty for doing so?