CompletionStage

Doug Lea dl at cs.oswego.edu
Mon Jul 1 08:21:35 PDT 2013


On 07/01/13 06:32, Doug Lea wrote:
> On 06/30/13 17:00, Sam Pullara wrote:
>> On Sun, Jun 30, 2013 at 1:34 PM, Doug Lea <dl at cs.oswego.edu
>>     They can (re)throw any exception they like when completed exceptionally.
>>
>>
>> This is really ugly.
>
> Thanks again for spotting this problem. Adding
> onExceptionalCompletion to cope, which pretty
> much forces adding onNormalCompletion for symmetry:

(I should have known that anything requiring dealing
with the delicate support for exceptions might take a
few tries...)

No, because this then branches inconsistently when you
contemplate asyncs. Better to have a unified handle()-like
version, and allow all three forms:

     /**
      * Returns a new CompletionStage with the same result or exception
      * as this stage, and when this stage completes, executes the
      * given action with the result (or {@code null} if none) and the
      * exception (or {@code null} if none) of this stage.
      *
      * @param action the action to perform
      */
     public CompletionStage<T> onCompletion
         (BiConsumer<? super T, ? super Throwable> action);

     /**
      * Returns a new CompletionStage with the same result or exception
      * as this stage, and when this stage completes, executes the
      * given action executes the given action using this stage's
      * default asynchronous execution facility, with the result (or
      * {@code null} if none) and the exception (or {@code null} if
      * none) of this stage as arguments.
      *
      * @param action the action to perform
      */
     public CompletionStage<T> onCompletionAsync
         (BiConsumer<? super T, ? super Throwable> action);

     /**
      * Returns a new CompletionStage with the same result or exception
      * as this stage, and when this stage completes, executes using
      * the supplied Executor, the given action with the result (or
      * {@code null} if none) and the exception (or {@code null} if
      * none) of this stage as arguments.
      *
      * @param action the action to perform
      */
     public CompletionStage<T> onCompletionAsync
         (BiConsumer<? super T, ? super Throwable> action,
          Executor executor);



More information about the lambda-libs-spec-experts mailing list