BaseObjectclass (see The Object Model) has methods for emitting and consuming events specific to the corresponding object instance. To emit an event from the object, use the
emit(...args)method. Use either the
on(name, ...args)method to consume the corresponding event a single time or any time it is emitted, respectively. Here is an example for emitting and consuming an event on an object.
Connection.open()method emits the opened event on the object instance. We can then register to receive the event, which is illustrated with we call the
conn.on()method. You can also use the
conn.once()if you only want to listener to be notified once when a connection is opened, and not every time the connection is opened.
EVENT_NAMEis the name of the event you are listening. The application event listeners must also extend the
Listenerclass in Blueprint. Here is an example of an application event listener responding to connection open events.
handleEvent()method. Similar to the object events, the
handleEvent()method takes a variable number of parameters. This count depends on the number of parameters passed to the
blueprint.emit()method instead of directly emitting on the local object instance. Here is an example emitting the connection open event as an application event.
emit()method is publishing the event a local object instance. The second
emit()is publishing the event on through the Blueprint application.
blueprint.once()to send and receive application events. Instead, you can use the
on()method on the application instance.
blueprint.app.init- Called after the application is initialized.
blueprint.app.started- Called after the application is started.
Promisereturned from the
emit()method to be resolved.
Promise. If the emitter is asynchronous, then it will not continue until the listener's promise is either resolved or rejected.