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.
| 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. |
Wraps a closure so that each invocation executes the body asynchronously and returns an Awaitable.
def asyncTask = AsyncClosureUtils.wrapAsync { expensiveWork()
def result = await asyncTask()
}
closure - the closure to wrapT - the result typeWraps a generator closure so that each invocation returns an Iterable backed by a GeneratorBridge.
closure - the generator closure; receives a GeneratorBridge
as its first parameterT - the element type