What is the correct way to convert a Kotlin suspend function to a function returning Mono?
A function already exists for this conversion. You need this dependency...
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-reactor</artifactId>
<version>1.6.0</version>
</dependency>
...and then you can do the following:
import kotlinx.coroutines.delay
import kotlinx.coroutines.reactor.mono
fun main() {
val mono = mono { doSomething(5) }
val result = mono.block()
println(result)
}
suspend fun doSomething(value: Int): String {
delay(1000L)
return "abc_$value"
}
In terms of threading you have nothing to worry about. Reactor is concurrency agnostic, so it can work with Kotlin coroutines threads just fine.