using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace ZeroLevel.Services.Async
{
	/// 
	/// Represents a thread-safe collection that allows asynchronous consuming.
	/// 
	/// The type of the items contained in the collection.
	public interface IAsyncCollection 
		: IReadOnlyCollection
	{
		/// 
		/// Gets an amount of pending item requests.
		/// 
		int AwaiterCount { get; }
		/// 
		/// Adds an item to the collection.
		/// 
		/// The item to add to the collection.
		void Add(T item);
		/// 
		/// Removes and returns an item from the collection in an asynchronous manner.
		/// 
		ValueTask TakeAsync(CancellationToken cancellationToken);
	}
	public static class AsyncCollectionExtensions
	{
		/// 
		/// Removes and returns an item from the collection in an asynchronous manner.
		/// 
		public static ValueTask TakeAsync(this IAsyncCollection collection)
		{
			return collection.TakeAsync(CancellationToken.None);
		}
	}
}