Package org.jtrim2.cancel
Interface InterruptibleTask<ResultType>
- Type Parameters:
ResultType- the type of the result of the task
public interface InterruptibleTask<ResultType>
Defines a generic task which can be canceled by interrupting the thread
executing the task. The task may respond to cancellation request either by
throwing an
InterruptedException or an
OperationCanceledException.-
Method Summary
Modifier and TypeMethodDescriptionexecute(CancellationToken cancelToken) Executes the task defined by thisInterruptibleTask.
-
Method Details
-
execute
Executes the task defined by thisInterruptibleTask. The task may choose to detect cancellation by means of the passedCancellationTokenor checking the interrupted status of the executing thread (or both).- Parameters:
cancelToken- theCancellationTokenwhich can be checked to detect cancellation requests. This task may also choose to ignore this argument and check the interrupted status of the executing thread. This argument cannot benull.- Returns:
- the return value of the task. This return value can be anything the task wishes
- Throws:
InterruptedException- the task may throw this exception in response to a cancellation requestOperationCanceledException- the task may throw this exception in response to a cancellation request
-