event

Event functions.

Example
var eventLib = require('/lib/xp/event');

Methods

(static) listener(params)

This function adds a event listener.

Parameters:
Name Type Description
params object

Listener parameters.

Properties
Name Type Description
type string

Event type pattern.

callback function

Callback event listener.

localOnly boolean

Local events only (default to false).

Example
// Adds an event listener on all node events.
eventLib.listener({
    type: 'node.*',
    localOnly: false,
    callback: function (event) {
        log.info(JSON.stringify(event));
    }
});

(static) send(event)

This function sends a custom event. All custom events are prefixed "custom.".

Parameters:
Name Type Description
event object

Event to send.

Properties
Name Type Description
type string

Event type.

distributed boolean

True if it should be distributed in cluster.

data object

Additional data for event.

Example
// Sends a custom event named "custom.myEvent".
eventLib.send({
    type: 'myEvent',
    distributed: false,
    data: {
        a: 1,
        b: 2
    }
});