Init
This commit is contained in:
60
ConsoleApp2/Services/DataRecordQueue.cs
Normal file
60
ConsoleApp2/Services/DataRecordQueue.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ConsoleApp2.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ConsoleApp2.Services;
|
||||
|
||||
public class DataRecordQueue
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicate that the queue is completed adding.
|
||||
/// </summary>
|
||||
public bool IsCompletedAdding { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remark that the queue is completed for adding and empty;
|
||||
/// </summary>
|
||||
public bool IsCompleted => IsCompletedAdding && _queue.IsEmpty;
|
||||
|
||||
private readonly ConcurrentQueue<DataRecord> _queue;
|
||||
|
||||
public DataRecordQueue()
|
||||
{
|
||||
_queue = new ConcurrentQueue<DataRecord>();
|
||||
}
|
||||
|
||||
public DataRecordQueue(IEnumerable<DataRecord> records)
|
||||
{
|
||||
_queue = new ConcurrentQueue<DataRecord>(records);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ConcurrentQueue{T}.Enqueue"/>
|
||||
public void Enqueue(DataRecord item)
|
||||
{
|
||||
_queue.Enqueue(item);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ConcurrentQueue{T}.TryDequeue"/>
|
||||
public bool TryDequeue([MaybeNullWhen(false)] out DataRecord result)
|
||||
{
|
||||
return _queue.TryDequeue(out result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ConcurrentQueue{T}.TryPeek"/>
|
||||
public bool TryPeek([MaybeNullWhen(false)] out DataRecord result)
|
||||
{
|
||||
return _queue.TryPeek(out result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ConcurrentQueue{T}.Count"/>
|
||||
public int Count => _queue.Count;
|
||||
|
||||
/// <inheritdoc cref="ConcurrentQueue{T}.IsEmpty"/>
|
||||
public bool IsEmpty => _queue.IsEmpty;
|
||||
|
||||
/// <summary>
|
||||
/// Indicate that the queue is completed adding.
|
||||
/// </summary>
|
||||
public void CompleteAdding() => IsCompletedAdding = true;
|
||||
}
|
Reference in New Issue
Block a user