using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace ZeroLevel.Services.Async { public interface IAsyncBatchCollection : IReadOnlyCollection> { int BatchSize { get; } void Add(T item); void Flush(); ValueTask> TakeAsync(CancellationToken cancellationToken); } public static class AsyncBatchCollectionExtensions { public static ValueTask> TakeAsync(this IAsyncBatchCollection collection) => collection.TakeAsync(CancellationToken.None); public static TimerAsyncBatchQueue WithFlushEvery(this IAsyncBatchCollection collection, TimeSpan flushPeriod) => new TimerAsyncBatchQueue(collection, flushPeriod); } }