mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 18:43:10 +08:00
Initial commit.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user