Package: org.apache.groovy.runtime.async

## [Java] Class DefaultAsyncScope

- org.apache.groovy.runtime.async.DefaultAsyncScope

- All Implemented Interfaces and Traits:
    AsyncScope

      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().

  See Also:
    AsyncScope
  Since:
    6.0.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `DefaultAsyncScope(Executor executor, boolean failFast)`
    `DefaultAsyncScope(Executor executor)`
    `DefaultAsyncScope()`

  - ### Methods Summary

    Methods
    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.

  - ### Inherited Methods Summary

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

- - ### Constructor Detail

    - #### public DefaultAsyncScope(Executor executor, boolean failFast)

    - #### public DefaultAsyncScope(Executor executor)

    - #### public DefaultAsyncScope()

  - ### Method Detail

    - #### <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. If the body does not complete within the duration, all children are cancelled and TimeoutException is thrown.