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
evtTEventThe event to publish.
ctCancellationTokenCancellation token to cancel the operation.
Returns
Type Parameters
TEventThe 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
evtTEventThe event to publish.
ctCancellationTokenCancellation token to cancel the operation.
Returns
Type Parameters
TEventThe 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
evtTEventThe event to publish.
ctCancellationTokenCancellation token to cancel the operation.
Type Parameters
TEventThe 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
evtTEventThe event to publish.
ctCancellationTokenCancellation token to cancel the operation.
Type Parameters
TEventThe 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
ownerobjectThe owner of the event bus, used for managing subscriptions.
handlerEventHandler<TEvent>Event handler to subscribe to the event bus.
handlerHashintOptional hash code for the handler, used to identify the subscription.
Returns
Type Parameters
TEventThe 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
ownerobjectOwner of the subscription, used for managing subscriptions.
handlerIEventListener<TEvent>Handler that implements IEventListener<TEvent> interface.
Returns
- IDisposable
An IDisposable that can be used to unsubscribe from the event.
Type Parameters
TEventThe 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
ownerobjectOwner of the subscription, used for managing subscriptions.
handlerAction<TEvent>Handler function that processes the event.
Returns
- IDisposable
An IDisposable that can be used to unsubscribe from the event.
Type Parameters
TEventThe 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
ownerobjectOwner of the subscription, used for managing subscriptions.
handlerFunc<TEvent, ValueTask>Handler function that processes the event.
Returns
- IDisposable
An IDisposable that can be used to unsubscribe from the event.
Type Parameters
TEventThe type of the event to subscribe to.
Unsubscribe(object)
Unsubscribe all handlers for the given owner.
public void Unsubscribe(object owner)
Parameters
ownerobjectOwner 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
ownerobjectOwner of the subscription, used for managing subscriptions.
handlerHashintHash 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
ownerobjectOwner of the subscription, used for managing subscriptions.
handlerEventHandler<TEvent>Handler function that processes the event.
Type Parameters
TEventThe 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
ownerobjectOwner of the subscription, used for managing subscriptions.
handlerIEventListener<TEvent>Handler that implements IEventListener<TEvent> interface.
Type Parameters
TEventThe 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
ownerobjectOwner of the subscription, used for managing subscriptions.
handlerAction<TEvent>Handler function that processes the event.
Type Parameters
TEventThe type of the event to unsubscribe from.