From 1760dc7d353e28cbc14ce81f44682b9902e499a3 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 21 Feb 2018 20:43:09 +0100 Subject: [PATCH] Fix async issues --- .../Server/MqttClientSession.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index c0e9e0c..91e5b8b 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -145,16 +145,16 @@ namespace MQTTnet.Server PendingMessagesQueue.Enqueue(publishPacket); } - public Task SubscribeAsync(IList topicFilters) + public async Task SubscribeAsync(IList topicFilters) { if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters)); - var response = SubscriptionsManager.SubscribeAsync(new MqttSubscribePacket + await SubscriptionsManager.SubscribeAsync(new MqttSubscribePacket { TopicFilters = topicFilters - }); + }).ConfigureAwait(false); - return response; + await EnqueueSubscribedRetainedMessagesAsync(topicFilters).ConfigureAwait(false); } public Task UnsubscribeAsync(IList topicFilters) @@ -270,7 +270,7 @@ namespace MQTTnet.Server await StopAsync().ConfigureAwait(false); } - await EnqueueSubscribedRetainedMessagesAsync(subscribePacket).ConfigureAwait(false); + await EnqueueSubscribedRetainedMessagesAsync(subscribePacket.TopicFilters).ConfigureAwait(false); } private async Task HandleIncomingUnsubscribePacketAsync(IMqttChannelAdapter adapter, MqttUnsubscribePacket unsubscribePacket, CancellationToken cancellationToken) @@ -279,12 +279,12 @@ namespace MQTTnet.Server await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, unsubscribeResult); } - private async Task EnqueueSubscribedRetainedMessagesAsync(MqttSubscribePacket subscribePacket) + private async Task EnqueueSubscribedRetainedMessagesAsync(ICollection topicFilters) { - var retainedMessages = await _retainedMessagesManager.GetSubscribedMessagesAsync(subscribePacket); - foreach (var publishPacket in retainedMessages) + var retainedMessages = await _retainedMessagesManager.GetSubscribedMessagesAsync(topicFilters); + foreach (var applicationMessage in retainedMessages) { - await EnqueueApplicationMessageAsync(publishPacket); + await EnqueueApplicationMessageAsync(applicationMessage).ConfigureAwait(false); } }