From 50381637af112c5e836946c8eb58b497d0a419c4 Mon Sep 17 00:00:00 2001 From: Nikita Senkov Date: Sun, 5 Sep 2021 12:49:52 +0300 Subject: [PATCH] Updated _ReconnectAsync_ extension methods to retrieve authentication result (#1202) --- Source/MQTTnet/Client/MqttClientExtensions.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/MQTTnet/Client/MqttClientExtensions.cs b/Source/MQTTnet/Client/MqttClientExtensions.cs index e9fd436..91a7c75 100644 --- a/Source/MQTTnet/Client/MqttClientExtensions.cs +++ b/Source/MQTTnet/Client/MqttClientExtensions.cs @@ -1,4 +1,4 @@ -using MQTTnet.Client.Connecting; +using MQTTnet.Client.Connecting; using MQTTnet.Client.Disconnecting; using MQTTnet.Client.ExtendedAuthenticationExchange; using MQTTnet.Client.Options; @@ -112,7 +112,7 @@ namespace MQTTnet.Client return client; } - public static Task ReconnectAsync(this IMqttClient client) + public static Task ReconnectAsync(this IMqttClient client) { if (client == null) throw new ArgumentNullException(nameof(client)); @@ -124,6 +124,18 @@ namespace MQTTnet.Client return client.ConnectAsync(client.Options); } + public static Task ReconnectAsync(this IMqttClient client, CancellationToken cancellationToken) + { + if (client == null) throw new ArgumentNullException(nameof(client)); + + if (client.Options == null) + { + throw new InvalidOperationException("_ReconnectAsync_ can be used only if _ConnectAsync_ was called before."); + } + + return client.ConnectAsync(client.Options, cancellationToken); + } + public static Task DisconnectAsync(this IMqttClient client) { if (client == null) throw new ArgumentNullException(nameof(client));