Package groovy.concurrent

# Interface AwaitableAdapter

All Known Implementing Classes:
  `FlowPublisherAdapter`, `ReactorAwaitableAdapter`, `RxJavaAwaitableAdapter`

public interface AwaitableAdapter
Service Provider Interface (SPI) for adapting third-party asynchronous types to Groovy's `Awaitable` abstraction and to iterables for `for await` loops.

Implementations are discovered automatically via `ServiceLoader`. To register an adapter, create a file `META-INF/services/groovy.concurrent.AwaitableAdapter` containing the fully-qualified class name of your implementation.

Since:
  6.0.0
See Also:
  - `AwaitableAdapterRegistry`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `supportsAwaitable(Class<?> type)`
  Returns `true` if this adapter can convert instances of the given type to `Awaitable` (single-value async result).
  `default boolean`
  `supportsIterable(Class<?> type)`
  Returns `true` if this adapter can convert instances of the given type to an `Iterable` for `for await` loops.
  `<T> Awaitable<T>`
  `toAwaitable(Object source)`
  Converts the given source object to an `Awaitable`.
  `default <T> Iterable<T>`
  `toIterable(Object source)`
  Converts the given source object to an `Iterable`.

- ## Method Details

  - ### supportsAwaitable

    boolean supportsAwaitable(Class<?> type)
    Returns `true` if this adapter can convert instances of the given type to `Awaitable` (single-value async result).

  - ### toAwaitable

    <T> Awaitable<T> toAwaitable(Object source)
    Converts the given source object to an `Awaitable`. Called only when `supportsAwaitable(java.lang.Class<?>)` returned `true`.

  - ### supportsIterable

    default boolean supportsIterable(Class<?> type)
    Returns `true` if this adapter can convert instances of the given type to an `Iterable` for `for await` loops. Defaults to `false`; override for multi-value async types (e.g., Reactor `Flux`, RxJava `Observable`).

  - ### toIterable

    default <T> Iterable<T> toIterable(Object source)
    Converts the given source object to an `Iterable`. Called only when `supportsIterable(java.lang.Class<?>)` returned `true`. The returned iterable typically blocks on `next()` until the next element is available — with virtual threads this is efficient.