(Quick Reference)

waitFor([long timeout, TimeUnit timeUnit, ], EventReply replies...)

Available in Controllers, Domains and Services

This method blocks for each passed reply until the relevant event has been processed, hence initializing the EventReply.value. It returns the same array of passed Event Replies for fluent programming style.

Usage

class SomeController{

   def logout(){
      def reply = event('logout', session.user)
      def reply2 = event('logout', session.user)
      def reply3 = event('logout', session.user)

      waitFor(reply,reply2,reply3).each{EventReply reply->
        render reply.value +'</br>'
      }

      //same with 20 seconds timeout on each reply
      waitFor(20, TimeUnit.SECONDS, reply,reply2,reply3).each{EventReply reply->
              render reply.value
      }

      //other style :
      event('logout', session.user).waitFor() //blocks event
      event('logout', session.user).waitFor(2000) //blocks event for maximum 2 seconds

   }
}

Arguments

NameMandatoryDefaultDescription
timeoutfalse app A timeout number associated to a time unit. E.g. 20
timeUnitfalse TimeUnit unit for timeout. E.g. TimeUnit.Second
repliestrue An EventReply list passed through multi-arg call style to block on each one.

You can directly call event and use the EventReply object to waitFor.