mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
Add async handlers for connect and disconnect, too
.. this allows a client to properly async publish on connect.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client.Connecting;
|
||||
using MQTTnet.Client.Disconnecting;
|
||||
using MQTTnet.Client.Publishing;
|
||||
using MQTTnet.Client.Receiving;
|
||||
using MQTTnet.Protocol;
|
||||
@@ -10,6 +12,30 @@ namespace MQTTnet.Extensions.ManagedClient
|
||||
{
|
||||
public static class ManagedMqttClientExtensions
|
||||
{
|
||||
public static IManagedMqttClient UseConnectedHandler(this IManagedMqttClient client, Func<MqttClientConnectedEventArgs, Task> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
client.ConnectedHandler = null;
|
||||
return client;
|
||||
}
|
||||
|
||||
client.ConnectedHandler = new MqttClientConnectedHandlerDelegate(handler);
|
||||
return client;
|
||||
}
|
||||
|
||||
public static IManagedMqttClient UseDisconnectedHandler(this IManagedMqttClient client, Func<MqttClientDisconnectedEventArgs, Task> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
{
|
||||
client.DisconnectedHandler = null;
|
||||
return client;
|
||||
}
|
||||
|
||||
client.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(handler);
|
||||
return client;
|
||||
}
|
||||
|
||||
public static IManagedMqttClient UseReceivedApplicationMessageHandler(this IManagedMqttClient client, Func<MqttApplicationMessageHandlerContext, Task> handler)
|
||||
{
|
||||
if (handler == null)
|
||||
|
||||
Reference in New Issue
Block a user