Interface StructuredTaskScope.Subtask<T>
- Type Parameters:
T- the result type
- All Superinterfaces:
Supplier<T>
- Enclosing interface:
StructuredTaskScope<T, R, R_X extends Throwable>
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
-
Nested Class Summary
Nested Classes -
Method Summary
-
Method Details
-
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 withfork(Callable)then the result of thecall()method is returned. If the subtask was forked withfork(Runnable)thennullis 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'sonComplete(Subtask)method. TheonComplete(Subtask)method should test that the state isSUCCESSbefore invoking theget()method to get the result.- Specified by:
getin interfaceSupplier<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 theonComplete(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 theCallable.call()orRunnable.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'sonComplete(Subtask)method. TheonComplete(Subtask)method should test that the state isFAILEDbefore 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 theonComplete(Subtask)method before the owner thread has joined- See Also:
-