using System; using System.Threading.Tasks; namespace MQTTnet.Extensions.ManagedClient { public class ConnectingFailedHandlerDelegate : IConnectingFailedHandler { private readonly Func _handler; public ConnectingFailedHandlerDelegate(Action handler) { if (handler == null) throw new ArgumentNullException(nameof(handler)); _handler = eventArgs => { handler(eventArgs); return Task.FromResult(0); }; } public ConnectingFailedHandlerDelegate(Func handler) { _handler = handler ?? throw new ArgumentNullException(nameof(handler)); } public Task HandleConnectingFailedAsync(ManagedProcessFailedEventArgs eventArgs) { return _handler(eventArgs); } } }