Package org.apache.groovy.runtime.async
Class AsyncClosureUtils
java.lang.Object
org.apache.groovy.runtime.async.AsyncClosureUtils
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.
- Since:
- 6.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionWraps a closure so that each invocation executes the body asynchronously and returns anAwaitable.wrapAsyncGenerator(Closure<?> closure) Wraps a generator closure so that each invocation returns anIterablebacked by aGeneratorBridge.
-
Method Details
-
wrapAsync
Wraps a closure so that each invocation executes the body asynchronously and returns anAwaitable.def asyncTask = AsyncClosureUtils.wrapAsync { expensiveWork() } def result = await asyncTask()- Type Parameters:
T- the result type- Parameters:
closure- the closure to wrap- Returns:
- a closure that returns an Awaitable on each call
-
wrapAsyncGenerator
Wraps a generator closure so that each invocation returns anIterablebacked by aGeneratorBridge.- Type Parameters:
T- the element type- Parameters:
closure- the generator closure; receives a GeneratorBridge as its first parameter- Returns:
- a closure that produces an Iterable on each call
-