AsyncTransformQueue<TInput, TOutput>

Namespace: SnowBank.Linq.Async.Iterators · class

Implements: IAsyncBuffer<TInput, TOutput>, IAsyncTarget<TInput>, IAsyncSource<TOutput>

Implements an async queue that asynchronously transform items, outputting them in arrival order, while throttling the producer

Constructors

AsyncTransformQueue<TInput, TOutput>

AsyncTransformQueue<TInput, TOutput>(Func<TInput, CancellationToken, Task<TOutput>> transform, int capacity, TaskScheduler scheduler)

Properties

Capacity

int Capacity { get; }

Returns the maximum capacity of the queue

Count

int Count { get; }

Returns the current number of items in the queue

IsConsumerBlocked

bool IsConsumerBlocked { get; }

Returns true if the producer is blocked (queue is full)

IsProducerBlocked

bool IsProducerBlocked { get; }

Returns true if the consumer is blocked (queue is empty)

Methods

DrainAsync

Task DrainAsync()

Wait for all the consumers to drain the queue

Returns: Task that completes when all consumers have drained the queue

OnCompleted

void OnCompleted()

Notifies the target that the producer is done and that no more values will be published

OnError

void OnError(ExceptionDispatchInfo error)

Notifies the target that tere was an exception, and that no more values will be published

  • error — The error that occurred

OnNextAsync

Task OnNextAsync(TInput value, CancellationToken ct)

Push a new item onto the target, if it can accept one

  • value — New value that is being published
  • ct — Cancellation token that is used to abort the call if the target is blocked

Returns: Task that completes once the target has accepted the new value (or fails if the cancellation token fires)

OnNextBatchAsync

Task OnNextBatchAsync(TInput[] batch, CancellationToken ct)

ReceiveAsync

Task<Maybe<TOutput>> ReceiveAsync(CancellationToken ct)

Consume a new value from the source

  • ct — Token used to cancel the operation

Returns: Task that will return a new value, nothing (if it has completed) or on exception

ReceiveBatchAsync

Task<Maybe<TOutput>[]> ReceiveBatchAsync(int count, CancellationToken ct)