Static ReadonlytelemetryStatic ReadonlywarningEmit a given event, causing all callback functions to be run in the order they were registered
The name of the event to emit
The argument to be passed to the callback function
Emit a telemetry event, causing all callback functions to be run in the order they were registered
The data to emit
Emit a warning event, causing all callback functions to be run in the order they were registered
Get an array of listeners (callback functions) for a given event
The name of the event to get listeners of
Create a new listener for a given event
The name of the event that is being listened for
The callback function to run when the event is emitted
OptionaluniqueListenerIdentifier: string
A unique identifier for the listener. If a listener with the same identifier is already registered, a new one will not be added
Create a listener for the telemetry event
The callback function to run when the event is emitted
Create a listener for the warning event
The callback function to run when the event is emitted
Remove all listeners for a given event
The name of the event to remove listeners of
return the package.json version of the sfdx-core library.
StaticgetRetrieve the singleton instance of this class so that all listeners and emitters can interact from any library or tool
Staticstaticreturn the package.json version of the sfdx-core library.
An asynchronous event listener and emitter that follows the singleton pattern. The singleton pattern allows lifecycle events to be emitted from deep within a library and still be consumed by any other library or tool. It allows other developers to react to certain situations or events in your library without them having to manually call the method themselves.
An example might be transforming metadata before it is deployed to an environment. As long as an event was emitted from the deploy library and you were listening on that event in the same process, you could transform the metadata before the deploy regardless of where in the code that metadata was initiated.
Example