Interface AsyncHandler.ParameterType<T>

Type Parameters:
T - the async type of the handler
Enclosing interface:
AsyncHandler

public static interface AsyncHandler.ParameterType<T>
A parameter type async handler is a service provider for this interface declared in META-INF/services. An async type of a parameter type async handler is the erasure of the type argument to the AsyncHandler.ParameterType direct superinterface type.

A target method matches a parameter type async handler when it declares exactly one parameter whose type's erasure is identical to the async type of the async handler. This parameter is called the async parameter.

See Also:
  • Method Details

    • transformArgument

      T transformArgument(T original, Runnable completion)
      Called once by Invoker.invoke(), before the target method is invoked.

      Takes the original argument value for the async parameter and returns a variant of it, transformed such that completion.run() is called on completion. The result is passed to the target method instead of the original.

      The net effect of this method and transformReturnValue(Object, Runnable) must be that completion.run() is called exactly once, after the asynchronous action completes. It is recommended that completion.run() is called before completion is propagated to the caller.

      Parameters:
      original - the original argument value for the async parameter
      completion - action that must be executed when the asynchronous action completes
      Returns:
      the transformed argument value for the async parameter
    • transformReturnValue

      default Object transformReturnValue(Object original, Runnable completion)
      Called once by Invoker.invoke(), after the target method returns. When the target method throws an exception synchronously, this method is not called.

      Takes the original return value and returns a variant of it, performing any transformation necessary such that that completion.run() is called on completion. The result is returned to the invoker caller instead of the original.

      The net effect of this method and transformArgument(Object, Runnable) must be that completion.run() is called exactly once, after the asynchronous action completes. It is recommended that completion.run() is called before completion is propagated to the caller.

      The default implementation returns original directly.

      Note that vast majority of parameter type async handlers do not need to implement this method, because completion is usually signaled solely through the async parameter. This method only needs to be implemented if the return value may also be used to signal completion. As of this writing, the only known situation when this occurs is Kotlin suspend functions, where synchronous completion is signaled through the return value and asynchronous completion is signaled through the Continuation parameter.

      Parameters:
      original - the original return value
      completion - action that must be executed when the asynchronous action completes
      Returns:
      the transformed return value