Table of Contents

Class EventBus

Namespace
Shard.Server.Modules
Assembly
Shard.Server.Modules.dll

Thread-safe IEventBus. Handlers are held per event type in an immutable array ordered by EventPriority so Publish<TEvent>(TEvent) is lock-free; subscribe/unsubscribe take a short write lock. A cancelled ICancellableEvent is skipped for handlers that did not opt into receiveCancelled. Synchronous handlers run inline; asynchronous handlers are awaited by PublishAsync<TEvent>(TEvent) (and run to completion under the synchronous Publish<TEvent>(TEvent)).

public sealed class EventBus : IEventBus
Inheritance
EventBus
Implements
Inherited Members

Methods

PublishAsync<TEvent>(TEvent)

Publish and await every subscriber (synchronous and asynchronous) in priority order.

public ValueTask PublishAsync<TEvent>(TEvent @event)

Parameters

event TEvent

Returns

ValueTask

Type Parameters

TEvent

Publish<TEvent>(TEvent)

Publish to all current subscribers in priority order; asynchronous handlers run to completion.

public void Publish<TEvent>(TEvent @event)

Parameters

event TEvent

Type Parameters

TEvent

SubscribeAsync<TEvent>(Func<TEvent, ValueTask>, EventPriority, bool)

Subscribe an asynchronous handler (awaited by PublishAsync<TEvent>(TEvent)).

public IDisposable SubscribeAsync<TEvent>(Func<TEvent, ValueTask> handler, EventPriority priority = EventPriority.Normal, bool receiveCancelled = false)

Parameters

handler Func<TEvent, ValueTask>
priority EventPriority
receiveCancelled bool

Returns

IDisposable

Type Parameters

TEvent

Subscribe<TEvent>(Action<TEvent>, EventPriority, bool)

Subscribe a synchronous handler; dispose the result to unsubscribe.

public IDisposable Subscribe<TEvent>(Action<TEvent> handler, EventPriority priority = EventPriority.Normal, bool receiveCancelled = false)

Parameters

handler Action<TEvent>
priority EventPriority
receiveCancelled bool

Returns

IDisposable

Type Parameters

TEvent