Table of Contents

Interface IEventBus

Namespace
Shard.Modding.SDK.Event
Assembly
Shard.Modding.SDK.dll

Publish/subscribe surface for server events. A module subscribes through its IModuleContext.Events so the subscription is scoped to the module and torn down automatically when the module shuts down.

Subscribers run in EventPriority order. A cancelled ICancellableEvent skips later subscribers unless they subscribed with receiveCancelled: true. Handlers may be synchronous (Subscribe<TEvent>(Action<TEvent>, EventPriority, bool)) or asynchronous (SubscribeAsync<TEvent>(Func<TEvent, ValueTask>, EventPriority, bool)); use PublishAsync<TEvent>(TEvent) to await asynchronous handlers without blocking the publisher.

Event convention: a plain type named SomethingEvent — a record struct for lightweight, non-cancellable notifications; a class implementing ICancellableEvent when cancellable.

public interface IEventBus

Methods

PublishAsync<TEvent>(TEvent)

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

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.

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

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.

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