PubSubExtensions
Namespace: SnowBank.Messaging.PubSub · class
Extensions methods for the IPubSub abstraction
Methods
ReadAllAsync
static IAsyncEnumerable<JsonValue> ReadAllAsync(IPubSub pubsub, string channel, CancellationToken ct)
Returns an IAsyncEnumerable that will read all messages received on a channel.
pubsub— Source of messageschannel— Channel to subscribe toct— Token used to stop reading from this channel
Returns: Enumerable that will asynchronously return all messages received on this channel, in sequential order.
The enumerator will never stop until either ct is triggered, or the caller disposes of the async enumerator.
SubscribeAsync
static Task<IAsyncDisposable> SubscribeAsync(IPubSub pubsub, string channel, ChannelWriter<JsonValue> writer, bool autoCompleteOnClose, CancellationToken ct)
Subscribes to a channel, and propagates all messages received to a Channel writer.
pubsub— Source of messageschannel— Channel to subscribe towriter— All message received will be written to this instanceautoCompleteOnClose— Iftrue, the methodTryCompletewill be called on the writer when the subscription is disposed.ct— Token used to forcefully abort the subscription.
Returns: Subscription token that must be disposed when the caller wants to cancel the subscription.
Any new message will be pumped into the channel , until either is triggered, or the caller invokes on the returned token.