Package org.apache.groovy.runtime.async
Class FlowPublisherAdapter
java.lang.Object
org.apache.groovy.runtime.async.FlowPublisherAdapter
- All Implemented Interfaces:
AwaitableAdapter
Adapter for
Flow.Publisher, the JDK's built-in
Reactive Streams type. Enables:
await publisherโ completes with the firstonNextvalue, then cancels the subscription. Completes withnullif the publisher signalsonCompletewithout emitting.for await (item in publisher)โ iterates over emitted values with bounded backpressure (seeDEFAULT_BATCH_SIZE).
Conformance:
- Reactive Streams ยง2.13:
onNext(null)is treated as a protocol violation and surfaced as aNullPointerException. - A second
onSubscribeafter the first is cancelled. - Signals after a terminal
onError/onCompleteare ignored.
This adapter is registered as the lowest-priority built-in (after SPI-loaded adapters) so framework-specific adapters (Reactor, RxJava) take precedence for their concrete types.
- Since:
- 6.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault request batch size forfor awaititeration. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleansupportsAwaitable(Class<?> type) Returnstrueif this adapter can convert instances of the given type toAwaitable(single-value async result).booleansupportsIterable(Class<?> type) Returnstrueif this adapter can convert instances of the given type to anIterableforfor awaitloops.<T> Awaitable<T>toAwaitable(Object source) Converts the given source object to anAwaitable.<T> Iterable<T>toIterable(Object source) Converts the given source object to anIterable.
-
Field Details
-
DEFAULT_BATCH_SIZE
public static final int DEFAULT_BATCH_SIZEDefault request batch size forfor awaititeration. Chosen as a compromise between throughput (larger = fewerrequest()calls) and memory (larger = bigger in-flight buffer). Override per-call by wrapping with a custom adapter if needed.- See Also:
-
-
Constructor Details
-
FlowPublisherAdapter
public FlowPublisherAdapter()
-
-
Method Details
-
supportsAwaitable
Description copied from interface:AwaitableAdapterReturnstrueif this adapter can convert instances of the given type toAwaitable(single-value async result).- Specified by:
supportsAwaitablein interfaceAwaitableAdapter
-
supportsIterable
Description copied from interface:AwaitableAdapterReturnstrueif this adapter can convert instances of the given type to anIterableforfor awaitloops. Defaults tofalse; override for multi-value async types (e.g., ReactorFlux, RxJavaObservable).- Specified by:
supportsIterablein interfaceAwaitableAdapter
-
toAwaitable
Description copied from interface:AwaitableAdapterConverts the given source object to anAwaitable. Called only whenAwaitableAdapter.supportsAwaitable(java.lang.Class<?>)returnedtrue.- Specified by:
toAwaitablein interfaceAwaitableAdapter
-
toIterable
Description copied from interface:AwaitableAdapterConverts the given source object to anIterable. Called only whenAwaitableAdapter.supportsIterable(java.lang.Class<?>)returnedtrue. The returned iterable typically blocks onnext()until the next element is available โ with virtual threads this is efficient.- Specified by:
toIterablein interfaceAwaitableAdapter
-