Interface AsyncHandler.ParameterType<T>
- Type Parameters:
T- the async type of the handler
- Enclosing interface:
- AsyncHandler
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.
-
Method Summary
Modifier and TypeMethodDescriptiontransformArgument(T original, Runnable completion) Called once byInvoker.invoke(), before the target method is invoked.default ObjecttransformReturnValue(Object original, Runnable completion) Called once byInvoker.invoke(), after the target method returns.
-
Method Details
-
transformArgument
Called once byInvoker.invoke(), before the target method is invoked.Takes the
originalargument value for the async parameter and returns a variant of it, transformed such thatcompletion.run()is called on completion. The result is passed to the target method instead of theoriginal.The net effect of this method and
transformReturnValue(Object, Runnable)must be thatcompletion.run()is called exactly once, after the asynchronous action completes. It is recommended thatcompletion.run()is called before completion is propagated to the caller.- Parameters:
original- the original argument value for the async parametercompletion- action that must be executed when the asynchronous action completes- Returns:
- the transformed argument value for the async parameter
-
transformReturnValue
Called once byInvoker.invoke(), after the target method returns. When the target method throws an exception synchronously, this method is not called.Takes the
originalreturn value and returns a variant of it, performing any transformation necessary such that thatcompletion.run()is called on completion. The result is returned to the invoker caller instead of theoriginal.The net effect of this method and
transformArgument(Object, Runnable)must be thatcompletion.run()is called exactly once, after the asynchronous action completes. It is recommended thatcompletion.run()is called before completion is propagated to the caller.The default implementation returns
originaldirectly.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
suspendfunctions, where synchronous completion is signaled through the return value and asynchronous completion is signaled through theContinuationparameter.- Parameters:
original- the original return valuecompletion- action that must be executed when the asynchronous action completes- Returns:
- the transformed return value
-