public final class DefaultAsyncScope
extends Object
implements AsyncScope
Default implementation of AsyncScope providing structured concurrency with configurable failure policy.
A dedicated lock guards the child task list and the closed flag jointly, ensuring that async(Closure) and close() cannot race. Child futures are registered under the lock before task submission (register-before-submit protocol), guaranteeing every child is joined or cancelled by close().
| Constructor and description |
|---|
DefaultAsyncScope(Executor executor, boolean failFast) |
DefaultAsyncScope(Executor executor) |
DefaultAsyncScope() |
| Type Params | Return Type | Name and description |
|---|---|---|
<T> |
public Awaitable<T> |
async(Closure<T> body) |
<T> |
public Awaitable<T> |
async(Supplier<T> supplier) |
|
public void |
cancelAll() |
|
public void |
close() |
|
public static AsyncScope |
current()Returns the current scope. |
|
public int |
getChildCount() |
|
public String |
toString() |
<T> |
public static T |
withCurrent(AsyncScope scope, Supplier<T> supplier)Executes the supplier with the given scope as current. |
Returns the current scope. Uses ScopedValue on JDK 25+,
ThreadLocal on earlier JDKs.
Executes the supplier with the given scope as current.
Uses ScopedValue.where().call() on JDK 25+ for
optimal virtual thread performance; falls back to
ThreadLocal set/restore on earlier JDKs.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.