From 9ff39c1fd920eac6d4b714278d68da65ac0e8d85 Mon Sep 17 00:00:00 2001 From: Paul Fake Date: Mon, 19 Nov 2018 21:11:47 -0500 Subject: [PATCH] New functions This is to support the peek-and-publish model for the managed client --- Source/MQTTnet/Internal/BlockingQueue.cs | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Source/MQTTnet/Internal/BlockingQueue.cs b/Source/MQTTnet/Internal/BlockingQueue.cs index d6c28f4..546b646 100644 --- a/Source/MQTTnet/Internal/BlockingQueue.cs +++ b/Source/MQTTnet/Internal/BlockingQueue.cs @@ -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.Default.Equals(_items.First.Value, item)) + { + _items.RemoveFirst(); + } + } + } public TItem RemoveFirst() {