-
public class TaskCompletionSource<TResult>Allows safe orchestration of a task's completion, preventing the consumer from prematurely completing the task. Essentially, it represents the producer side of a Task, providing access to the consumer side through the getTask() method while isolating the Task's completion mechanisms from the consumer.
-
-
Constructor Summary
Constructors Constructor Description TaskCompletionSource()Creates a TaskCompletionSource that orchestrates a Task.
-
Method Summary
Modifier and Type Method Description Task<TResult>getTask()booleantrySetCancelled()Sets the cancelled flag on the Task if the Task hasn't already been completed. booleantrySetResult(TResult result)Sets the result on the Task if the Task hasn't already been completed. booleantrySetError(Exception error)Sets the error on the Task if the Task hasn't already been completed. voidsetCancelled()Sets the cancelled flag on the task, throwing if the Task has already been completed. voidsetResult(TResult result)Sets the result of the Task, throwing if the Task has already been completed. voidsetError(Exception error)Sets the error of the Task, throwing if the Task has already been completed. -
-
Method Detail
-
trySetCancelled
boolean trySetCancelled()
Sets the cancelled flag on the Task if the Task hasn't already been completed.
-
trySetResult
boolean trySetResult(TResult result)
Sets the result on the Task if the Task hasn't already been completed.
-
trySetError
boolean trySetError(Exception error)
Sets the error on the Task if the Task hasn't already been completed.
-
setCancelled
void setCancelled()
Sets the cancelled flag on the task, throwing if the Task has already been completed.
-
setResult
void setResult(TResult result)
Sets the result of the Task, throwing if the Task has already been completed.
-
-
-
-