Table of Contents

Class EventBus

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

Represents an event bus that allows publishing and subscribing to events.

public sealed class EventBus : IEventBus, IPluginComponent, IManageable<PluginComponentsManager>, IManageable, IEventBusPublisher, IEventBusSubscriber, IDisposable
Inheritance
EventBus
Implements
Inherited Members
Extension Methods

Methods

Dispose()

Disposes the event bus, clearing all subscriptions.

public void Dispose()

PublishAsync<TEvent>(TEvent, CancellationToken)

Publishes an event asynchronously to all subscribers of the specified event type.

public ValueTask PublishAsync<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent

Parameters

evt TEvent

The event to publish.

ct CancellationToken

The cancellation token to observe while publishing the event.

Returns

ValueTask

Type Parameters

TEvent

The type of the event to publish.

Exceptions

AggregateException

Thrown if any of the event handlers throw an exception.

PublishSafeAsync<TEvent>(TEvent, CancellationToken)

Publishes an event asynchronously to all subscribers of the specified event type, catching any exceptions.

public ValueTask PublishSafeAsync<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent

Parameters

evt TEvent

The event to publish.

ct CancellationToken

The cancellation token to observe while publishing the event.

Returns

ValueTask

Type Parameters

TEvent

The type of the event to publish.

PublishSafe<TEvent>(TEvent, CancellationToken)

Publishes an event synchronously to all subscribers of the specified event type, catching any exceptions.

public void PublishSafe<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent

Parameters

evt TEvent

The event to publish.

ct CancellationToken

The cancellation token to observe while publishing the event.

Type Parameters

TEvent

The type of the event to publish.

Publish<TEvent>(TEvent, CancellationToken)

Publishes an event synchronously to all subscribers of the specified event type.

public void Publish<TEvent>(TEvent evt, CancellationToken ct = default) where TEvent : IEvent

Parameters

evt TEvent

The event to publish.

ct CancellationToken

The cancellation token to observe while publishing the event.

Type Parameters

TEvent

The type of the event to publish.

Subscribe<TEvent>(EventHandler<TEvent>)

Subscribes a handler to the event bus for a specific event type.

public IDisposable Subscribe<TEvent>(EventHandler<TEvent> handler) where TEvent : IEvent

Parameters

handler EventHandler<TEvent>

Handler to subscribe to the event.

Returns

IDisposable

An IDisposable that can be used to unsubscribe the handler.

Type Parameters

TEvent

The type of the event to subscribe to.

Subscribe<TEvent>(IEventListener<TEvent>)

Subscribes a handler to the event bus for a specific event type using an IEventListener<TEvent>.

public IDisposable Subscribe<TEvent>(IEventListener<TEvent> handler) where TEvent : IEvent

Parameters

handler IEventListener<TEvent>

Handler to subscribe to the event.

Returns

IDisposable

An IDisposable that can be used to unsubscribe the handler.

Type Parameters

TEvent

The type of the event to subscribe to.

Subscribe<TEvent>(Action<TEvent>)

Subscribes a handler to the event bus for a specific event type.

public IDisposable Subscribe<TEvent>(Action<TEvent> handler) where TEvent : IEvent

Parameters

handler Action<TEvent>

Handler to subscribe to the event.

Returns

IDisposable

An IDisposable that can be used to unsubscribe the handler.

Type Parameters

TEvent

The type of the event to subscribe to.

Subscribe<TEvent>(Func<TEvent, ValueTask>)

Subscribes a handler to the event bus for a specific event type.

public IDisposable Subscribe<TEvent>(Func<TEvent, ValueTask> handler) where TEvent : IEvent

Parameters

handler Func<TEvent, ValueTask>

Handler to subscribe to the event.

Returns

IDisposable

An IDisposable that can be used to unsubscribe the handler.

Type Parameters

TEvent

The type of the event to subscribe to.

Unsubscribe<TEvent>(EventHandler<TEvent>)

Unsubscribes a handler from the event bus for a specific event type.

public void Unsubscribe<TEvent>(EventHandler<TEvent> handler) where TEvent : IEvent

Parameters

handler EventHandler<TEvent>

Handler to unsubscribe from the event.

Type Parameters

TEvent

The type of the event to unsubscribe from.