Table of Contents

Delegate AsyncEventHandler<TArgs>

Namespace
Nyra
Assembly
Nyra.dll

Asynchronous event handler. Unlike EventHandler<TEventArgs>, a handler may await inside its body without becoming async void, because the raiser awaits the returned task.

public delegate Task AsyncEventHandler<TArgs>(object? sender, TArgs args) where TArgs : EventArgs

Parameters

sender object

Origin of the event.

args TArgs

Event payload.

Returns

Task

Task that completes when the handler finished its work.

Type Parameters

TArgs

Event payload type.

Remarks

Handlers of one event run in subscription order and one throwing does not stop the rest, the exception goes to the raise's error callback, except an OperationCanceledException, which is swallowed as cooperative cancellation. Raise by awaiting each entry of GetInvocationList(), a plain multicast invoke observes only the last handler's task.

The events of one owner (a node, a guild connection, the extension) share one queue. A handler that never returns stalls it, and once 4096 events are pending the next ones are dropped (the high-frequency ones already past 512) with a single warning, so a stuck handler cannot grow the process without bound.

The type parameter is invariant on purpose. A variance conversion would let one delegate instance subscribe to several events, and the multicast combine then throws an ArgumentException or a removal silently no-ops.