Package org.apache.groovy.rxjava
Class RxJavaAwaitableAdapter
java.lang.Object
org.apache.groovy.rxjava.RxJavaAwaitableAdapter
- All Implemented Interfaces:
AwaitableAdapter
Adapter for RxJava 3 types, enabling:
await single— awaits aSingleawait maybe— awaits aMaybe(nullable result)await completable— awaits aCompletablefor await (item in observable)— iterates over anObservablefor await (item in flowable)— iterates over aFlowable
Auto-discovered via ServiceLoader when groovy-rxjava
is on the classpath.
- Since:
- 6.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleansupportsAwaitable(Class<?> type) Returns whether the supplied type can be awaited as an RxJava single-result source.booleansupportsIterable(Class<?> type) Returns whether the supplied type can be exposed as an iterable RxJava multi-result source.<T> Awaitable<T>toAwaitable(Object source) Converts supported RxJava single-result sources into anAwaitable.<T> Iterable<T>toIterable(Object source) Converts supported RxJava multi-result sources into blocking iterables suitable forfor awaitconsumption.
-
Constructor Details
-
RxJavaAwaitableAdapter
public RxJavaAwaitableAdapter()
-
-
Method Details
-
supportsAwaitable
Returns whether the supplied type can be awaited as an RxJava single-result source.- Specified by:
supportsAwaitablein interfaceAwaitableAdapter- Parameters:
type- candidate type to inspect- Returns:
trueiftypeis aSingle,Maybe,Completable, or one of their subtypes
-
toAwaitable
Converts supported RxJava single-result sources into anAwaitable. ASingleyields its item, aMaybeyields its item ornullwhen empty, and aCompletablecompletes withnull.- Specified by:
toAwaitablein interfaceAwaitableAdapter- Type Parameters:
T- awaited value type- Parameters:
source- source object to adapt- Returns:
- awaitable representation of the supplied source
- Throws:
IllegalArgumentException- ifsourceis not a supported RxJava type
-
supportsIterable
Returns whether the supplied type can be exposed as an iterable RxJava multi-result source.- Specified by:
supportsIterablein interfaceAwaitableAdapter- Parameters:
type- candidate type to inspect- Returns:
trueiftypeis anObservable,Flowable, or one of their subtypes
-
toIterable
Converts supported RxJava multi-result sources into blocking iterables suitable forfor awaitconsumption.- Specified by:
toIterablein interfaceAwaitableAdapter- Type Parameters:
T- iterated element type- Parameters:
source- source object to adapt- Returns:
- iterable representation of the supplied
ObservableorFlowable - Throws:
IllegalArgumentException- ifsourceis not a supported RxJava type
-