This controller implements pub/sub pattern and serves as a broker (event bus) between event emitter (publisher) and event consumer (subscriber). https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern
Methods
# static publish(event, payload, waitAsync) → {Array}
This function calls all callbacks that subscribed to the specific event
Parameters:
Name | Type | Description |
---|---|---|
event |
EzraEvent | Event key to be notified |
payload |
* | |
waitAsync |
Boolean | Whether or not the function should wait for the subscribers (default: false) |
Array of callback results
# static publishAsync(event, payload) → {Promise.<Array>}
This function calls all callbacks that subscribed to the specific event and awaits for all callbacks to finish
Parameters:
Name | Type | Description |
---|---|---|
event |
EzraEvent | Event key to be notified |
payload |
* |
Promise that resolves to array of callback results
# static subscribe(event, callback, prioritize) → {Subscription}
This function subscribes callback to be called when future events are published
Parameters:
Name | Type | Description |
---|---|---|
event |
EzraEvent | Event key to be notified on publish |
callback |
SubscribedCallback | Function to call when when event is published |
prioritize |
Boolean | Whether or not this callback should be prioritized when the event is published |
subscription
# static subscribeMultiple(callback) → {Subscription}
This function subscribes on multiple events, so that the callback function gets called when any of those future events are published.
Parameters:
Name | Type | Description |
---|---|---|
callback |
SubscribedCallback | Function to call when events are published |
subscription
# static subscribePrioritized(event, callback) → {Subscription}
This function subscribes callback to be called when future events are published. The subscriber is handled with priority by inserting it on top of the subscriber list.
Parameters:
Name | Type | Description |
---|---|---|
event |
EzraEvent | Event key to be notified on publish |
callback |
SubscribedCallback | Function to call when when event is published |
subscription