Initial commit.

This commit is contained in:
Christian Kratky
2017-03-19 18:41:29 +01:00
parent bc50796f9d
commit 9b720d2325
70 changed files with 3487 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
using System;
using System.Threading.Tasks;
using MQTTnet.Core.Packets;
namespace MQTTnet.Core.Client
{
public class MqttPacketAwaiter
{
private readonly TaskCompletionSource<MqttBasePacket> _taskCompletionSource = new TaskCompletionSource<MqttBasePacket>();
private readonly Func<MqttBasePacket, bool> _packetSelector;
public MqttPacketAwaiter(Func<MqttBasePacket, bool> packetSelector)
{
if (packetSelector == null) throw new ArgumentNullException(nameof(packetSelector));
_packetSelector = packetSelector;
}
public Task<MqttBasePacket> Task => _taskCompletionSource.Task;
public bool CheckPacket(MqttBasePacket packet)
{
if (!_packetSelector(packet))
{
return false;
}
_taskCompletionSource.SetResult(packet);
return true;
}
}
}