Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-563

Event.fireAsync() - clarify the usage of the returned CompletionStage

    XMLWordPrintable

Details

    • Clarification
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Done
    • 2.0-EDR1
    • 2.0 .Final
    • Events
    • None

    Description

      So far CompletionStage is only mentioned in "10.5.1. Handling multiple exceptions thrown during an asynchronous event" and the Event.fireAsync() javadoc is too general. However, the CompletionStage itself does not define an unambiguous contract for its methods. E.g. what thread is used to execute a given callback? Or what's the "stage's default asynchronous execution facility"? I believe this is left on implementors. In Weld 3.0 Alpha we're using CompletableFuture under the hood, and its more concrete in this area, e.g.:

      • Actions supplied for dependent completions of non-async methods may be performed by the thread that completes the current CompletableFuture, or by any other caller of a completion method.

      So as a result, if an async delivery is finished before a sync dependent action is registered, the callback is executed in the caller thread:

      event.fireAsync(new Message()).thenAccept((m) -> System.out.println("This might be executed in a caller thread or in a different thread!"));
      

      And this might be confusing. Especially from the context propagation point of view. I think the spec should clarify the contract of a returned CompletionStage.

      Attachments

        Issue Links

          Activity

            People

              asabotdu@redhat.com Antoine Sabot-Durand (Inactive)
              mkouba@redhat.com Martin Kouba
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: