[cdi-dev] [JBoss JIRA] (CDI-729) Async event not CompletionStage friendly

Martin Kouba (JIRA) issues at jboss.org
Mon Jun 18 08:56:00 EDT 2018


    [ https://issues.jboss.org/browse/CDI-729?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13592677#comment-13592677 ] 

Martin Kouba commented on CDI-729:
----------------------------------

Well, observers are not designed to return anything. If you return some object it is just ignored. The reason is that observers were designed for decoupled communication. Ideally, observers should NOT depend on each other and emitters should NOT depend on observers either.

In your example, the observer which saves the entity could throw an exception if something goes wrong so that the {{CompletionStage}} returned from {{fire()}} would end up exceptionally. Of course, if you need to perform the save action asynchronously you'd probably have to fire another async event when it's done and declare another async observer for this particular event.

> Async event not CompletionStage friendly
> ----------------------------------------
>
>                 Key: CDI-729
>                 URL: https://issues.jboss.org/browse/CDI-729
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>            Reporter: Romain Manni-Bucau
>
> The goal of this ticket is to enable user to get injected the completion future instead of the raw event and return another completion stage (generic type ignored) to enable the "chain" to be synched.
> Here is a sample:
> 1. fireAsync(persistEvent)
> 2. observer implementation does: return future.thenCompose(db::doAsyncPersist)
> 3. when the user gets back the result of the fireAsync the doAsyncPersist is completed.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the cdi-dev mailing list