Property OnSubscribed
OnSubscribed
Invoked when the subscription has been established, that is, once the SUB protocol message has been queued for sending to the server. This is the same guarantee SubscribeCoreAsync<T>(string, string?, INatsDeserialize<T>?, NatsSubOpts?, CancellationToken) provides when it completes.
public Func<NatsSubBase, ValueTask>? OnSubscribed { get; init; }
Property Value
Remarks
The async enumerable returned by SubscribeAsync<T>(string, string?, INatsDeserialize<T>?, NatsSubOpts?, CancellationToken) does not establish the subscription until it is iterated. When the enumerable is handed off to another task, use this callback (for example, to complete a TaskCompletionSource<TResult>) to find out when it is safe to trigger messages the subscription must observe. Publishers using other connections may still race with the server processing the subscription; a PingAsync(CancellationToken) round-trip on the subscribing connection after this callback removes that race.
The callback receives the subscription and is invoked once when the subscription is first established; it is not invoked again when subscriptions are re-established after a reconnect. If the callback throws, the subscription is disposed and the exception propagates to the subscribe call.