Package org.springframework.core

# Class CoroutinesUtils

java.lang.Object
org.springframework.core.CoroutinesUtils

public abstract class CoroutinesUtils extends Object
Utilities for working with Kotlin Coroutines.

Since:
  5.2
Author:
  Sebastien Deleuze, Phillip Webb

## Constructor Summary

Constructors
Constructor
Description
`CoroutinesUtils()`

## Method Summary

Modifier and Type
Method
Description
`static <T> reactor.core.publisher.Mono<T>`
`deferredToMono(kotlinx.coroutines.Deferred<T> source)`
Convert a `Deferred` instance to a `Mono`.
`static Publisher<?>`
`invokeSuspendingFunction(Method method, Object target, Object... args)`
Invoke a suspending function and convert it to `Mono` or `Flux`.
`static Publisher<?>`
`invokeSuspendingFunction(kotlin.coroutines.CoroutineContext context, Method method, Object target, Object... args)`
Invoke a suspending function and convert it to `Mono` or `Flux`.
`static <T> kotlinx.coroutines.Deferred<T>`
`monoToDeferred(reactor.core.publisher.Mono<T> source)`
Convert a `Mono` instance to a `Deferred`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CoroutinesUtils

public CoroutinesUtils()

## Method Details

### deferredToMono

public static <T> reactor.core.publisher.Mono<T> deferredToMono(kotlinx.coroutines.Deferred<T> source)
Convert a `Deferred` instance to a `Mono`.

### monoToDeferred

public static <T> kotlinx.coroutines.Deferred<T> monoToDeferred(reactor.core.publisher.Mono<T> source)
Convert a `Mono` instance to a `Deferred`.

### invokeSuspendingFunction

public static Publisher<?> invokeSuspendingFunction(Method method, Object target, @Nullable Object... args)
Invoke a suspending function and convert it to `Mono` or `Flux`. Uses an unconfined dispatcher.

Parameters:
  `method` - the suspending function to invoke
  `target` - the target to invoke `method` on
  `args` - the function arguments. If the `Continuation` argument is specified as the last argument (typically `null`), it is ignored.
Returns:
  the method invocation result as reactive stream
Throws:
  `IllegalArgumentException` - if `method` is not a suspending function

### invokeSuspendingFunction

public static Publisher<?> invokeSuspendingFunction(kotlin.coroutines.CoroutineContext context, Method method, @Nullable Object target, @Nullable Object... args)
Invoke a suspending function and convert it to `Mono` or `Flux`.

Parameters:
  `context` - the coroutine context to use
  `method` - the suspending function to invoke
  `target` - the target to invoke `method` on
  `args` - the function arguments. If the `Continuation` argument is specified as the last argument (typically `null`), it is ignored.
Returns:
  the method invocation result as reactive stream
Throws:
  `IllegalArgumentException` - if `method` is not a suspending function
Since:
  6.0