Class EventBus
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
eventTEvent
Returns
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
eventTEvent
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
handlerFunc<TEvent, ValueTask>priorityEventPriorityreceiveCancelledbool
Returns
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
handlerAction<TEvent>priorityEventPriorityreceiveCancelledbool
Returns
Type Parameters
TEvent