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