Interface StructuredTaskScope.Subtask<T>

Type Parameters:
T - the result type
All Superinterfaces:
Supplier<T>
Enclosing interface:
StructuredTaskScope<T, R, R_X extends Throwable>

public static sealed interface StructuredTaskScope.Subtask<T> extends Supplier<T>
Represents a subtask forked in a StructuredTaskScope with fork(Callable) or fork(Runnable).

The scope owner can use the get() method after joining to obtain the result of a subtask that completed successfully. It can use the exception() method to obtain the exception of a failed subtask.

Since:
28
  • Method Details

    • state

      Returns the subtask state.
      Returns:
      the subtask state
    • get

      T get()
      Returns the result of this subtask if it completed successfully. If the scope is cancelled, the subtask completed successfully before the scope was cancelled. If the subtask was forked with fork(Callable) then the result of the call() method is returned. If the subtask was forked with fork(Runnable) then null is returned.

      This method may be invoked by any thread after the scope owner has joined. The only case where this method may be used to get the result before the scope owner has joined is when called from a Joiner's onComplete(Subtask) method. The onComplete(Subtask) method should test that the state is SUCCESS before invoking the get() method to get the result.

      Specified by:
      get in interface Supplier<T>
      API Note:
      This method does not wait for the subtask to complete.
      Returns:
      the possibly-null result
      Throws:
      IllegalStateException - if the subtask has not completed or did not complete successfully, or this method is invoked outside the context of the onComplete(Subtask) method before the owner thread has joined
      See Also:
    • exception

      Throwable exception()
      Returns the exception or error for this subtask if it failed. If the scope is cancelled, the subtask failed before the scope was cancelled. If the subtask executed, then the exception or error thrown by the Callable.call() or Runnable.run() method is returned.

      This method may be invoked by any thread after the scope owner has joined. The only case where this method may be used before the scope owner has joined is when called from a Joiner's onComplete(Subtask) method. The onComplete(Subtask) method should test that the state is FAILED before invoking this method.

      API Note:
      This method does not wait for the subtask to complete.
      Returns:
      the exception or error for this subtask if it failed
      Throws:
      IllegalStateException - if the subtask has not completed or completed with a result, or this method is invoked outside the context of the onComplete(Subtask) method before the owner thread has joined
      See Also: