2 Replies Latest reply on Dec 2, 2016 7:25 PM by ljnelson

    ObservesAsync: reception not guaranteed?

    ljnelson

      I have a bean like this:

       

      @ApplicationScoped

      public class Foo {

         private Bar bar;

         @Inject

         public void initMethod(final Bar bar) {

           System.out.println("*** initializing"); // prints first, always

          this.bar = bar;

         }

       

         public void observeScopeInitialization(@ObservesAsync @Initialized(ApplicationScoped.class) final Object payload) {

           System.out.println("*** scope initialized"); // never prints when async; prints fine when synchronous

         }

      }

       

      The initialization method prints its message no matter what, as I'd expect.  The observer method does not.  If I change the observer method parameter to be annotated with @Observes instead of @ObservesAsync, it prints its message.

       

      Is this expected behavior?  I am guessing that the container never "got around" to scheduling delivery of the event before it was shut down in my brief stupid unit test—what I'm not clear on is whether this is permitted by the specification or not.

       

      Weld SE core version 3.0.0 Alpha 17 if it matters.