Table of Contents

Class ManagedEventBus

Namespace
RisingV.Shared.Events
Assembly
RisingV.Shared.dll

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 TEvent

The event to publish.

ct CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

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 TEvent

The event to publish.

ct CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

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 TEvent

The event to publish.

ct CancellationToken

Cancellation 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 TEvent

The event to publish.

ct CancellationToken

Cancellation 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 object

The owner of the event bus, used for managing subscriptions.

handler EventHandler<TEvent>

Event handler to subscribe to the event bus.

handlerHash int

Optional hash code for the handler, used to identify the subscription.

Returns

IDisposable

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 object

Owner 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 object

Owner 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 object

Owner 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 object

Owner 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 object

Owner of the subscription, used for managing subscriptions.

handlerHash int

Hash 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 object

Owner 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 object

Owner 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 object

Owner 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.