Package org.apache.groovy.rxjava

# Class RxJavaAwaitableAdapter

java.lang.Object
org.apache.groovy.rxjava.RxJavaAwaitableAdapter

All Implemented Interfaces:
  `AwaitableAdapter`

public class RxJavaAwaitableAdapter extends Object implements AwaitableAdapter
Adapter for RxJava 3 types, enabling:

- `await single` — awaits a `Single`
- `await maybe` — awaits a `Maybe` (nullable result)
- `await completable` — awaits a `Completable`
- `for await (item in observable)` — iterates over an `Observable`
- `for await (item in flowable)` — iterates over a `Flowable`

Auto-discovered via `ServiceLoader` when `groovy-rxjava` is on the classpath.

Since:
  6.0.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RxJavaAwaitableAdapter()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `supportsAwaitable(Class<?> type)`
  Returns whether the supplied type can be awaited as an RxJava single-result source.
  `boolean`
  `supportsIterable(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 an `Awaitable`.
  `<T> Iterable<T>`
  `toIterable(Object source)`
  Converts supported RxJava multi-result sources into blocking iterables suitable for `for await` consumption.

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

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

- ## Constructor Details

  - ### RxJavaAwaitableAdapter

    public RxJavaAwaitableAdapter()

- ## Method Details

  - ### supportsAwaitable

    public boolean supportsAwaitable(Class<?> type)
    Returns whether the supplied type can be awaited as an RxJava single-result source.
    Specified by:
      `supportsAwaitable` in interface `AwaitableAdapter`
    Parameters:
      `type` - candidate type to inspect
    Returns:
      `true` if `type` is a `Single`, `Maybe`, `Completable`, or one of their subtypes

  - ### toAwaitable

    public <T> Awaitable<T> toAwaitable(Object source)
    Converts supported RxJava single-result sources into an `Awaitable`. A `Single` yields its item, a `Maybe` yields its item or `null` when empty, and a `Completable` completes with `null`.
    Specified by:
      `toAwaitable` in interface `AwaitableAdapter`
    Type Parameters:
      `T` - awaited value type
    Parameters:
      `source` - source object to adapt
    Returns:
      awaitable representation of the supplied source
    Throws:
      `IllegalArgumentException` - if `source` is not a supported RxJava type

  - ### supportsIterable

    public boolean supportsIterable(Class<?> type)
    Returns whether the supplied type can be exposed as an iterable RxJava multi-result source.
    Specified by:
      `supportsIterable` in interface `AwaitableAdapter`
    Parameters:
      `type` - candidate type to inspect
    Returns:
      `true` if `type` is an `Observable`, `Flowable`, or one of their subtypes

  - ### toIterable

    public <T> Iterable<T> toIterable(Object source)
    Converts supported RxJava multi-result sources into blocking iterables suitable for `for await` consumption.
    Specified by:
      `toIterable` in interface `AwaitableAdapter`
    Type Parameters:
      `T` - iterated element type
    Parameters:
      `source` - source object to adapt
    Returns:
      iterable representation of the supplied `Observable` or `Flowable`
    Throws:
      `IllegalArgumentException` - if `source` is not a supported RxJava type