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(Supplier) 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)Creates a scope that runs children on executor.
|
DefaultAsyncScope(Executor executor)Creates a scope on executor with fail-fast cancellation enabled.
|
DefaultAsyncScope()Creates a fail-fast scope on AsyncSupport.getExecutor. |
| Type Params | Return Type | Name and description |
|---|---|---|
<T> |
public Awaitable<T> |
async(Supplier<T> supplier) |
|
public void |
cancelAll() |
|
public void |
close() |
|
public static AsyncScope |
current()Returns the current scope, or null when no scope is bound. |
|
public int |
getChildCount() |
|
public AsyncScope |
getParent() |
|
public String |
toString() |
<T> |
public static T |
withCurrent(AsyncScope scope, Supplier<T> supplier)Executes the supplier with the given scope as current, restoring the previous binding afterwards. |
<T> |
public static T |
withScopeTimeout(Executor executor, Duration timeout, Function<AsyncScope, T> body)Creates a scope with a timeout. |
Creates a scope that runs children on executor.
executor must be non-null. When failFast is true, a child that
completes with an error cancels the other registered children with interrupt,
unless the scope is already closed. The parent is current(). When that
parent is a DefaultAsyncScope and is not closed, this scope is registered
as its child. No task is started here.
executor - the executor used for child tasksfailFast - whether a failed child cancels the other registered children Creates a scope on executor with fail-fast cancellation enabled.
Equivalent to DefaultAsyncScope(Executor, boolean) DefaultAsyncScope(executor, true).
A null executor fails immediately.
executor - the executor used for child tasksCreates a fail-fast scope on AsyncSupport.getExecutor. Equivalent to DefaultAsyncScope(AsyncSupport.getExecutor(), true).
Returns the current scope, or null when no scope is bound.
Executes the supplier with the given scope as current, restoring the previous binding afterwards.
Creates a scope with a timeout. If the body does not complete within the duration, all children are cancelled and TimeoutException is thrown.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.