Browse Source

New functions

This is to support the peek-and-publish model for the managed client
release/3.x.x
Paul Fake 6 years ago
committed by GitHub
parent
commit
9ff39c1fd9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions
  1. +32
    -0
      Source/MQTTnet/Internal/BlockingQueue.cs

+ 32
- 0
Source/MQTTnet/Internal/BlockingQueue.cs 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()
{


Loading…
Cancel
Save