stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace StellaOps.Provcache;
|
||||
|
||||
public sealed partial class WriteBehindQueue
|
||||
{
|
||||
private async Task DrainAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var batch = new List<WriteBehindItem>();
|
||||
|
||||
while (_channel.Reader.TryRead(out var item))
|
||||
{
|
||||
batch.Add(item);
|
||||
Interlocked.Decrement(ref _currentQueueDepth);
|
||||
|
||||
if (batch.Count >= _options.WriteBehindBatchSize)
|
||||
{
|
||||
await ProcessBatchAsync(batch, cancellationToken).ConfigureAwait(false);
|
||||
batch.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (batch.Count > 0)
|
||||
{
|
||||
await ProcessBatchAsync(batch, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Write-behind queue drained");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user