@ -18,6 +18,7 @@
package org.springframework.core
package org.springframework.core
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.async
import kotlinx.coroutines.reactive.awaitFirstOrNull
import kotlinx.coroutines.reactive.awaitFirstOrNull
@ -36,7 +37,8 @@ import kotlin.reflect.jvm.kotlinFunction
* @author Sebastien Deleuze
* @author Sebastien Deleuze
* @since 5.2
* @since 5.2
* /
* /
internal fun < T : Any > deferredToMono ( source : Deferred < T > ) = GlobalScope . mono { source . await ( ) }
internal fun < T : Any > deferredToMono ( source : Deferred < T > ) =
GlobalScope . mono ( Dispatchers . Unconfined ) { source . await ( ) }
/ * *
/ * *
* Convert a [ Mono ] instance to a [ Deferred ] one .
* Convert a [ Mono ] instance to a [ Deferred ] one .
@ -44,7 +46,8 @@ internal fun <T: Any> deferredToMono(source: Deferred<T>) = GlobalScope.mono { s
* @author Sebastien Deleuze
* @author Sebastien Deleuze
* @since 5.2
* @since 5.2
* /
* /
internal fun < T : Any > monoToDeferred ( source : Mono < T > ) = GlobalScope . async { source . awaitFirstOrNull ( ) }
internal fun < T : Any > monoToDeferred ( source : Mono < T > ) =
GlobalScope . async ( Dispatchers . Unconfined ) { source . awaitFirstOrNull ( ) }
/ * *
/ * *
* Invoke an handler method converting suspending method to [ Mono ] if necessary .
* Invoke an handler method converting suspending method to [ Mono ] if necessary .
@ -55,7 +58,8 @@ internal fun <T: Any> monoToDeferred(source: Mono<T>) = GlobalScope.async { sour
internal fun invokeHandlerMethod ( method : Method , bean : Any , vararg args : Any ? ) : Any ? {
internal fun invokeHandlerMethod ( method : Method , bean : Any , vararg args : Any ? ) : Any ? {
val function = method . kotlinFunction !!
val function = method . kotlinFunction !!
return if ( function . isSuspend ) {
return if ( function . isSuspend ) {
GlobalScope . mono { function . callSuspend ( bean , * args . sliceArray ( 0. . ( args . size - 2 ) ) )
GlobalScope . mono ( Dispatchers . Unconfined ) {
function . callSuspend ( bean , * args . sliceArray ( 0. . ( args . size - 2 ) ) )
. let { if ( it == Unit ) null else it } }
. let { if ( it == Unit ) null else it } }
. onErrorMap ( InvocationTargetException :: class ) { it . targetException }
. onErrorMap ( InvocationTargetException :: class ) { it . targetException }
}
}