mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
New functions
This is to support the peek-and-publish model for the managed client
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user