Package: org.apache.groovy.runtime.async

## [Java] Class AsyncClosureUtils

- org.apache.groovy.runtime.async.AsyncClosureUtils

-     public final class AsyncClosureUtils
      extends Object

  Closure-specific async utilities that have no pure-Java equivalent.

  These methods create Closure subclasses and are therefore inherently Groovy-specific. They predate the `async` keyword and are retained for programmatic use. The `async { ... }` keyword syntax is preferred for most use cases.

  See Also:
    AsyncSupport
  Since:
    6.0.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `<T>` | `public static Closure<Awaitable<T>>` | `wrapAsync(Closure<T> closure)` Wraps a closure so that each invocation executes the body asynchronously and returns an Awaitable.
    `<T>` | `public static Closure<Iterable<T>>` | `wrapAsyncGenerator(Closure<?> closure)` Wraps a generator closure so that each invocation returns an Iterable backed by a GeneratorBridge.

  - ### Inherited Methods Summary

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

- - ### Method Detail

    - #### <T> public static Closure<Awaitable<T>> wrapAsync(Closure<T> closure)

      Wraps a closure so that each invocation executes the body asynchronously and returns an Awaitable.

          def asyncTask = AsyncClosureUtils.wrapAsync { expensiveWork() }
           def result = await asyncTask()

      Parameters:
        `closure` - the closure to wrap
      Type Parameters:
        `T` - the result type
      Returns:
        a closure that returns an Awaitable on each call

    - #### <T> public static Closure<Iterable<T>> wrapAsyncGenerator(Closure<?> closure)

      Wraps a generator closure so that each invocation returns an Iterable backed by a GeneratorBridge.

      Parameters:
        `closure` - the generator closure; receives a GeneratorBridge as its first parameter
      Type Parameters:
        `T` - the element type
      Returns:
        a closure that produces an Iterable on each call