<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />

Nito.AsyncEx.AsyncCollection<T>

public sealed class AsyncCollection<T>
An async-compatible producer/consumer collection.
public AsyncCollection(IProducerConsumerCollection<T> collection, int maxCount)

Creates a new async-compatible producer/consumer collection wrapping the specified collection and with a maximum element count.

Creates a new async-compatible producer/consumer collection wrapping the specified collection.

public AsyncCollection(int maxCount)

Creates a new async-compatible producer/consumer collection with a maximum element count.

public AsyncCollection()

Creates a new async-compatible producer/consumer collection.

public void Add(T item, CancellationToken cancellationToken)

Adds an item to the producer/consumer collection. Throws InvalidOperationException if the producer/consumer collection has completed adding or if the item was rejected by the underlying collection. This method may block the calling thread.

public void Add(T item)

Adds an item to the producer/consumer collection. Throws InvalidOperationException if the producer/consumer collection has completed adding or if the item was rejected by the underlying collection. This method may block the calling thread.

public Task AddAsync(T item, CancellationToken cancellationToken)

Adds an item to the producer/consumer collection. Throws InvalidOperationException if the producer/consumer collection has completed adding or if the item was rejected by the underlying collection.

public Task AddAsync(T item)

Adds an item to the producer/consumer collection. Throws InvalidOperationException if the producer/consumer collection has completed adding or if the item was rejected by the underlying collection.

public void CompleteAdding()

Synchronously marks the producer/consumer collection as complete for adding.

Provides a (synchronous) consuming enumerable for items in the producer/consumer collection.

Provides a (synchronous) consuming enumerable for items in the producer/consumer queue.

public bool OutputAvailable(CancellationToken cancellationToken)

Synchronously waits until an item is available to take. Returns false if the producer/consumer collection has completed adding and there are no more items.

public bool OutputAvailable()

Synchronously waits until an item is available to take. Returns false if the producer/consumer collection has completed adding and there are no more items.

public Task<bool> OutputAvailableAsync(CancellationToken cancellationToken)

Asynchronously waits until an item is available to take. Returns false if the producer/consumer collection has completed adding and there are no more items.

public Task<bool> OutputAvailableAsync()

Asynchronously waits until an item is available to take. Returns false if the producer/consumer collection has completed adding and there are no more items.

public T Take(CancellationToken cancellationToken)

Takes an item from the producer/consumer collection. Returns the item. Throws InvalidOperationException if the producer/consumer collection has completed adding and is empty, or if the take from the underlying collection failed. This method may block the calling thread.

public T Take()

Takes an item from the producer/consumer collection. Returns the item. Throws InvalidOperationException if the producer/consumer collection has completed adding and is empty, or if the take from the underlying collection failed. This method may block the calling thread.

public Task<T> TakeAsync(CancellationToken cancellationToken)

Takes an item from the producer/consumer collection. Returns the item. Throws InvalidOperationException if the producer/consumer collection has completed adding and is empty, or if the take from the underlying collection failed.

public Task<T> TakeAsync()

Takes an item from the producer/consumer collection. Returns the item. Throws InvalidOperationException if the producer/consumer collection has completed adding and is empty, or if the take from the underlying collection failed.