Package 

Class TaskCompletionSource


  • 
    public class TaskCompletionSource<TResult extends Object>
    
                        

    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<TResult>, providing access to the consumer side through the getTask() method while isolating the Task's completion mechanisms from the consumer. </TResult>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Task<TResult> task
    • Method Summary

      Modifier and Type Method Description
      final Task<TResult> getTask()
      final Boolean trySetCancelled() Sets the cancelled flag on the Task if the Task hasn't already been completed.
      final Boolean trySetResult(TResult result) Sets the result on the Task if the Task hasn't already been completed.
      final Boolean trySetError(Exception error) Sets the error on the Task if the Task hasn't already been completed.
      final Unit setCancelled() Sets the cancelled flag on the task, throwing if the Task has already been completed.
      final Unit setResult(TResult result) Sets the result of the Task, throwing if the Task has already been completed.
      final Unit setError(Exception error) Sets the error of the Task, throwing if the Task has already been completed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TaskCompletionSource

        TaskCompletionSource()
    • Method Detail

      • trySetCancelled

         final Boolean trySetCancelled()

        Sets the cancelled flag on the Task if the Task hasn't already been completed.

      • setCancelled

         final Unit setCancelled()

        Sets the cancelled flag on the task, throwing if the Task has already been completed.

      • setResult

         final Unit setResult(TResult result)

        Sets the result of the Task, throwing if the Task has already been completed.

      • setError

         final Unit setError(Exception error)

        Sets the error of the Task, throwing if the Task has already been completed.