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

Romain Manni-Bucau (JIRA) issues at jboss.org
Mon Jun 18 08:30:00 EDT 2018

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

Romain Manni-Bucau commented on CDI-729:

If the observer execute some reactive code returning a CompletionStage there is no way in current spec to chain the CompletionStage of the processing to the event firing to ensure it is executed before returning. This makes the whole API quite useless and requires to define another way to fire event and compose them.

public CompletionStage<Entity> save(Entity e);

fireAsync(new Persist(entity))

How do you compose both?

What you want is:

CompletionStage<?> onPersist(@ObserveAsync CompletionStage<Persist> persist) {
  return persist.thenCompose(event -> repo.save(event.getEntity());

This way the fireAsync ensures the persistence is done:

event.fireAsync(new Persist(entity))
  .thenApply(event -> log.info("{} persisted", event.getEntity()));

> 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

More information about the cdi-dev mailing list