Class ManagedEventBus
Represents a managed event bus that allows subscribing and publishing events.
public class ManagedEventBus : IEventBus, IPluginComponent, IManageable<PluginComponentsManager>, IManageable, IEventBusPublisher, IEventBusManagedSubscriber
- Inheritance
-
ManagedEventBus
- Implements
- Inherited Members
- Extension Methods
Methods
Dispose()
Disposes the event bus and all its subscriptions.
public void Dispose()
PublishAsync<TEvent>(TEvent, CancellationToken)
Publish an event asynchronously to all subscribers.
public ValueTask PublishAsync<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent
Parameters
evt
TEventThe event to publish.
ct
CancellationTokenCancellation token to cancel the operation.
Returns
Type Parameters
TEvent
The type of the event to publish.
PublishSafeAsync<TEvent>(TEvent, CancellationToken)
Publish an event asynchronously to all subscribers, with error handling.
public ValueTask PublishSafeAsync<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent
Parameters
evt
TEventThe event to publish.
ct
CancellationTokenCancellation token to cancel the operation.
Returns
Type Parameters
TEvent
The type of the event to publish.
PublishSafe<TEvent>(TEvent, CancellationToken)
Publish an event synchronously to all subscribers, with error handling.
public void PublishSafe<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent
Parameters
evt
TEventThe event to publish.
ct
CancellationTokenCancellation token to cancel the operation.
Type Parameters
TEvent
The type of the event to publish.
Publish<TEvent>(TEvent, CancellationToken)
Publish an event synchronously to all subscribers.
public void Publish<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent
Parameters
evt
TEventThe event to publish.
ct
CancellationTokenCancellation token to cancel the operation.
Type Parameters
TEvent
The type of the event to publish.
Subscribe<TEvent>(object, EventHandler<TEvent>, int)
Initializes a new instance of the ManagedEventBus class.
public IDisposable Subscribe<TEvent>(object owner, EventHandler<TEvent> handler, int handlerHash = 0) where TEvent : IEvent
Parameters
owner
objectThe owner of the event bus, used for managing subscriptions.
handler
EventHandler<TEvent>Event handler to subscribe to the event bus.
handlerHash
intOptional hash code for the handler, used to identify the subscription.
Returns
Type Parameters
TEvent
The type of the event to subscribe to.
Subscribe<TEvent>(object, IEventListener<TEvent>)
Subscribe a handler and receive an IDisposable that will unsubscribe when disposed.
public IDisposable Subscribe<TEvent>(object owner, IEventListener<TEvent> handler) where TEvent : IEvent
Parameters
owner
objectOwner of the subscription, used for managing subscriptions.
handler
IEventListener<TEvent>Handler that implements IEventListener<TEvent> interface.
Returns
- IDisposable
An IDisposable that can be used to unsubscribe from the event.
Type Parameters
TEvent
The type of the event to subscribe to.
Subscribe<TEvent>(object, Action<TEvent>)
Subscribe a handler and receive an IDisposable that will unsubscribe when disposed.
public IDisposable Subscribe<TEvent>(object owner, Action<TEvent> handler) where TEvent : IEvent
Parameters
owner
objectOwner of the subscription, used for managing subscriptions.
handler
Action<TEvent>Handler function that processes the event.
Returns
- IDisposable
An IDisposable that can be used to unsubscribe from the event.
Type Parameters
TEvent
The type of the event to subscribe to.
Subscribe<TEvent>(object, Func<TEvent, ValueTask>)
Subscribe a handler and receive an IDisposable that will unsubscribe when disposed.
public IDisposable Subscribe<TEvent>(object owner, Func<TEvent, ValueTask> handler) where TEvent : IEvent
Parameters
owner
objectOwner of the subscription, used for managing subscriptions.
handler
Func<TEvent, ValueTask>Handler function that processes the event.
Returns
- IDisposable
An IDisposable that can be used to unsubscribe from the event.
Type Parameters
TEvent
The type of the event to subscribe to.
Unsubscribe(object)
Unsubscribe all handlers for the given owner.
public void Unsubscribe(object owner)
Parameters
owner
objectOwner of the subscriptions to unsubscribe.
Unsubscribe(object, int)
Unsubscribe a handler from the event bus using the owner and handler hash.
protected void Unsubscribe(object owner, int handlerHash)
Parameters
owner
objectOwner of the subscription, used for managing subscriptions.
handlerHash
intHash code of the handler to unsubscribe.
Unsubscribe<TEvent>(object, EventHandler<TEvent>)
Unsubscribe a handler from the event bus.
public void Unsubscribe<TEvent>(object owner, EventHandler<TEvent> handler) where TEvent : IEvent
Parameters
owner
objectOwner of the subscription, used for managing subscriptions.
handler
EventHandler<TEvent>Handler function that processes the event.
Type Parameters
TEvent
The type of the event to unsubscribe from.
Unsubscribe<TEvent>(object, IEventListener<TEvent>)
Unsubscribe a handler from the event bus.
public void Unsubscribe<TEvent>(object owner, IEventListener<TEvent> handler) where TEvent : IEvent
Parameters
owner
objectOwner of the subscription, used for managing subscriptions.
handler
IEventListener<TEvent>Handler that implements IEventListener<TEvent> interface.
Type Parameters
TEvent
The type of the event to unsubscribe from.
Unsubscribe<TEvent>(object, Action<TEvent>)
Unsubscribe a handler from the event bus.
public void Unsubscribe<TEvent>(object owner, Action<TEvent> handler) where TEvent : IEvent
Parameters
owner
objectOwner of the subscription, used for managing subscriptions.
handler
Action<TEvent>Handler function that processes the event.
Type Parameters
TEvent
The type of the event to unsubscribe from.