Utilities: BlockingQueue.TryDequeue: Change behavior to return all items enqueued before Stop was invoked

This commit is contained in:
Tal Aloni 2025-05-01 21:37:48 +03:00
parent 21313ac030
commit a9ec1878d0

View file

@ -17,6 +17,11 @@ namespace Utilities
public void Enqueue(T item)
{
if (m_stopping)
{
return;
}
lock (m_queue)
{
m_queue.Enqueue(item);
@ -30,10 +35,11 @@ namespace Utilities
public void Enqueue(List<T> items)
{
if (items.Count == 0)
if (m_stopping || items.Count == 0)
{
return;
}
lock (m_queue)
{
foreach (T item in items)
@ -60,7 +66,7 @@ namespace Utilities
Monitor.Wait(m_queue);
}
if (m_stopping)
if (m_stopping && m_queue.Count == 0)
{
item = default(T);
return false;
@ -82,6 +88,15 @@ namespace Utilities
}
}
public void Abort()
{
lock (m_queue)
{
m_queue.Clear();
Stop();
}
}
public int Count
{
get