MixedConsumerProducerContext<T> Class

Provides a context for MixedConsumerProducer that allows enqueuing additional items to be processed.

public sealed class MixedConsumerProducerContext<T>

Type parameters

T
The type of items to process.

Methods

NameDescription
Enqueue(T)Enqueues an item to be processed.
EnqueueAsync(T, CancellationToken)Enqueues an item to be processed, waiting while MixedConsumerProducerOptions.MaxPendingItems items are pending.
TryEnqueue(T)Tries to enqueue an item to be processed without waiting.

Enqueues an item to be processed.

public void Enqueue(T item)

Parameters

item T
The item to enqueue.

Exceptions

InvalidOperationException
The item cannot be enqueued, for instance because MixedConsumerProducerOptions.MaxPendingItems items are already pending. Use MixedConsumerProducerContext<T>.EnqueueAsync to wait instead.

EnqueueAsync(T, CancellationToken)

MixedConsumerProducerContext.cs

Enqueues an item to be processed, waiting while MixedConsumerProducerOptions.MaxPendingItems items are pending.

public ValueTask EnqueueAsync(T item, CancellationToken cancellationToken = default)

Parameters

item T
The item to enqueue.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

ValueTask A task that completes once the item is enqueued, or once it is processed when every consumer would wait for room.

Exceptions

OperationCanceledException
cancellationToken or the token of the processing was canceled.
InvalidOperationException
The processing is completed.

Remarks

When every consumer would wait for room, nothing could dequeue an item anymore. In that case the item is processed by the caller before this method returns, and an exception thrown while processing it is reported by MixedConsumerProducer.Process like the exceptions of the other items.

Tries to enqueue an item to be processed without waiting.

public bool TryEnqueue(T item)

Parameters

item T
The item to enqueue.

Returns

bool true if the item is enqueued; false if it cannot be enqueued, for instance because MixedConsumerProducerOptions.MaxPendingItems items are already pending.