New functions

This is to support the peek-and-publish model for the managed client
This commit is contained in:
Paul Fake
2018-11-19 21:11:47 -05:00
committed by GitHub
parent 210d57b254
commit 9ff39c1fd9
+32
View File
@@ -55,6 +55,38 @@ namespace MQTTnet.Internal
_gate.WaitOne();
}
}
public TItem PeekAndWait()
{
while (true)
{
lock (_syncRoot)
{
if (_items.Count > 0)
{
return _items.First.Value;
}
if (_items.Count == 0)
{
_gate.Reset();
}
}
_gate.WaitOne();
}
}
public void RemoveFirstIfEqual(TItem item)
{
lock (_syncRoot)
{
if (_items.Count > 0 && EqualityComparer<TItem>.Default.Equals(_items.First.Value, item))
{
_items.RemoveFirst();
}
}
}
public TItem RemoveFirst()
{