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
| Name | Description |
|---|---|
| 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. |
Enqueue(T)
MixedConsumerProducerContext.csEnqueues an item to be processed.
public void Enqueue(T item)Parameters
itemT- The item to enqueue.
Exceptions
InvalidOperationException- The item cannot be enqueued, for instance because
MixedConsumerProducerOptions.MaxPendingItemsitems are already pending. UseMixedConsumerProducerContext<T>.EnqueueAsyncto wait instead.
EnqueueAsync(T, CancellationToken)
MixedConsumerProducerContext.csEnqueues an item to be processed, waiting while MixedConsumerProducerOptions.MaxPendingItems items are pending.
public ValueTask EnqueueAsync(T item, CancellationToken cancellationToken = default)Parameters
itemT- The item to enqueue.
cancellationTokenCancellationToken- 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
OperationCanceledExceptioncancellationTokenor 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.
TryEnqueue(T)
MixedConsumerProducerContext.csTries to enqueue an item to be processed without waiting.
public bool TryEnqueue(T item)Parameters
itemT- 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.