Package: org.apache.groovy.runtime.async

## [Java] Class GeneratorBridge<T>

- org.apache.groovy.runtime.async.GeneratorBridge

- All Implemented Interfaces and Traits:
    Iterator, Closeable

      public final class GeneratorBridge<T>
      extends Object
      implements Iterator, Closeable

  A producer/consumer bridge for async generators (`yield return`).

  The generator closure runs on a separate thread and calls yield(Object) to produce values. The consumer iterates using hasNext()/next(). A SynchronousQueue provides the handoff — each `yield` blocks until the consumer takes the value, providing natural back-pressure.

  With virtual threads (JDK 21+), both the producer and consumer block cheaply. On JDK 17-20, the producer runs on a platform thread from the cached pool.

  Type Parameters:
    `T` - the element type
  Since:
    6.0.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `close()`
    `` | `public boolean` | `hasNext()`
    `` | `public T` | `next()`
    `` | `public void` | `yield(Object value)` Called by the generator (producer thread) to yield a value.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public void close()

    - #### public boolean hasNext()

    - #### public T next()

    - #### public void yield(Object value)

      Called by the generator (producer thread) to yield a value. Blocks until the consumer calls next().

      throws:
        GeneratorClosedException if the consumer has closed the bridge
      Parameters:
        `value` - the value to yield (may be null)