Any artifact that holds a reference to the current application may trigger events at its leisure by calling the event()
or eventAsync
methods on the application instance. The following example demonstrates how a Controller triggers a "Done" event after an action has finishedclass MyController {
def action = { evt = null ->
// do some work
app.event('Done')
}
}
There are two versions of the event()
method. The first takes just the name of the event to be published; the second accepts an additional argument which should be a List of parameters to be sent to every event handler. Event handlers notified by this method are guaranteed to process the event in the same thread that published it. However, if what you need is to post a new event and return immediately then use the eventAsync
variants. If you want the event to be handled outside of the UI thread then use the eventOutsideUI()
variants.