Use Task.WhenAll to handle errors in both tasks.

Previously if there was an exception in the first task that is awaited the second task would not be awaited.
This commit is contained in:
Johan x Lindqvist
2019-09-16 11:33:37 +02:00
parent ad1c198e43
commit ba9ceed7ce
+4 -2
View File
@@ -269,8 +269,10 @@ namespace MQTTnet.Client
await _adapter.DisconnectAsync(Options.CommunicationTimeout, CancellationToken.None).ConfigureAwait(false);
}
await WaitForTaskAsync(_packetReceiverTask, sender).ConfigureAwait(false);
await WaitForTaskAsync(_keepAlivePacketsSenderTask, sender).ConfigureAwait(false);
var receiverTask = WaitForTaskAsync(_packetReceiverTask, sender);
var keepAliveTask = WaitForTaskAsync(_keepAlivePacketsSenderTask, sender);
await Task.WhenAll(receiverTask, keepAliveTask).ConfigureAwait(false);
_logger.Verbose("Disconnected from adapter.");
}