title: Converting Mono to a coroutine an then back again in WebFlux + Kotlin
body: <p>I have a project with Spring WebFlux and normally we use Kotlin coroutines and don't see many <code>Mono</code> or <code>Flux</code> around. However, from time to time the need arises to integrate with the framework, like implement a custom <code>ReactiveAuthorizationManager</code> 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:</p>
  <pre class="lang-kotlin prettyprint-override"><code>fun someFunction(fooMono: Mono&lt;Foo&gt;): Mono&lt;Bar&gt; {
    return mono {
      val foo = fooMono.awaitSingleOrNull()
      // do stuff
      Bar(...)
    }
  }
  </code></pre>
  <p>which uses Reactor coroutines integration. The code (<code>do stuff</code> above) is then much (in my opinion) easier to understand and can actually be debugged.</p>
  <p>Basically it converts a <code>Mono</code> to a coroutine and then back again. Is this a good idea? Is there a big performance penalty for doing so?</p>