Class: PluginEventBus
Defined in: src/plugins/core/event-bus.ts:117
Plugin event bus implementation.
Remarks
Provides a pub/sub event system for plugin hooks built on EventEmitter2. Features include:
- Wildcard event patterns (
preprint.*) - Namespace delimiter (
.) - Error isolation per handler
- Handler cleanup tracking
- Async event emission
Example
const eventBus = container.resolve(PluginEventBus);
// Subscribe to all preprint events
eventBus.on('preprint.*', (data) => {
console.log('Preprint event:', data);
});
// Emit specific event
eventBus.emit('preprint.indexed', { uri, title });
// Emit and wait for all handlers
await eventBus.emitAsync('preprint.indexed', { uri, title });
Implements
Constructors
new PluginEventBus()
new PluginEventBus(
logger):PluginEventBus
Defined in: src/plugins/core/event-bus.ts:141
Creates a new PluginEventBus.
Parameters
logger
Logger instance for event bus logging
Returns
Methods
emit()
emit(
event, ...args):void
Defined in: src/plugins/core/event-bus.ts:299
Emits an event synchronously.
Parameters
event
string
Event name
args
...readonly unknown[]
Arguments to pass to handlers
Returns
void
Remarks
This emits the event but doesn't wait for async handlers to complete. Use emitAsync if you need to wait for all handlers.
Example
eventBus.emit('preprint.indexed', {
uri: 'at://did:plc:abc/pub.chive.preprint.submission/xyz',
title: 'My Preprint',
});
Implementation of
emitAsync()
emitAsync(
event, ...args):Promise<void>
Defined in: src/plugins/core/event-bus.ts:326
Emits an event and waits for all handlers to complete.
Parameters
event
string
Event name
args
...readonly unknown[]
Arguments to pass to handlers
Returns
Promise<void>
Promise resolving when all handlers complete
Example
await eventBus.emitAsync('preprint.indexed', {
uri: 'at://did:plc:abc/pub.chive.preprint.submission/xyz',
title: 'My Preprint',
});
console.log('All handlers completed');
Implementation of
eventNames()
eventNames():
string[]
Defined in: src/plugins/core/event-bus.ts:394
Gets all event names with listeners.
Returns
string[]
Array of event names
Implementation of
listenerCount()
listenerCount(
event):number
Defined in: src/plugins/core/event-bus.ts:383
Gets listener count for an event pattern.
Parameters
event
string
Event name or pattern
Returns
number
Number of listeners
Implementation of
off()
off(
event,handler):void
Defined in: src/plugins/core/event-bus.ts:349
Unsubscribes from an event.
Parameters
event
string
Event name
handler
(...args) => void
Handler function to remove
Returns
void
Example
const handler = (data) => console.log(data);
eventBus.on('preprint.indexed', handler);
// Later...
eventBus.off('preprint.indexed', handler);
Implementation of
on()
on(
event,handler):void
Defined in: src/plugins/core/event-bus.ts:177
Subscribes to an event.
Parameters
event
string
Event name or pattern (supports wildcards like 'preprint.*')
handler
(...args) => void
Event handler function
Returns
void
Remarks
Handlers are wrapped to isolate errors. If a handler throws, the error is logged but doesn't affect other handlers or crash the event bus.
Example
// Subscribe to specific event
eventBus.on('preprint.indexed', (data) => {
console.log('Indexed:', data.uri);
});
// Subscribe to all preprint events
eventBus.on('preprint.*', (data) => {
console.log('Preprint event:', data);
});
Implementation of
once()
once(
event,handler):void
Defined in: src/plugins/core/event-bus.ts:236
Subscribes to an event for one-time execution.
Parameters
event
string
Event name or pattern
handler
(...args) => void
Event handler function (called once then removed)
Returns
void
Example
eventBus.once('system.startup', () => {
console.log('System started');
});
Implementation of
removeAllListeners()
removeAllListeners():
void
Defined in: src/plugins/core/event-bus.ts:406
Removes all listeners.
Returns
void
Remarks
Use during shutdown to clean up all event subscriptions.
Implementation of
IPluginEventBus.removeAllListeners
removeAllListenersForEvent()
removeAllListenersForEvent(
event):void
Defined in: src/plugins/core/event-bus.ts:420
Removes all listeners for a specific event.
Parameters
event
string
Event name to clear
Returns
void