mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
760 B
23 lines
760 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ZeroLevel.Services.Async
|
|
{
|
|
public interface IAsyncBatchCollection<T> : IReadOnlyCollection<IReadOnlyList<T>>
|
|
{
|
|
int BatchSize { get; }
|
|
|
|
void Add(T item);
|
|
void Flush();
|
|
ValueTask<IReadOnlyList<T>> TakeAsync(CancellationToken cancellationToken);
|
|
}
|
|
|
|
public static class AsyncBatchCollectionExtensions
|
|
{
|
|
public static ValueTask<IReadOnlyList<T>> TakeAsync<T>(this IAsyncBatchCollection<T> collection) => collection.TakeAsync(CancellationToken.None);
|
|
public static TimerAsyncBatchQueue<T> WithFlushEvery<T>(this IAsyncBatchCollection<T> collection, TimeSpan flushPeriod) => new TimerAsyncBatchQueue<T>(collection, flushPeriod);
|
|
}
|
|
}
|