You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
1.0 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. namespace MQTTnet.Extensions.ManagedClient
  4. {
  5. public class ApplicationMessageProcessedHandlerDelegate : IApplicationMessageProcessedHandler
  6. {
  7. private readonly Func<ApplicationMessageProcessedEventArgs, Task> _handler;
  8. public ApplicationMessageProcessedHandlerDelegate(Action<ApplicationMessageProcessedEventArgs> handler)
  9. {
  10. if (handler == null) throw new ArgumentNullException(nameof(handler));
  11. _handler = context =>
  12. {
  13. handler(context);
  14. return Task.FromResult(0);
  15. };
  16. }
  17. public ApplicationMessageProcessedHandlerDelegate(Func<ApplicationMessageProcessedEventArgs, Task> handler)
  18. {
  19. _handler = handler ?? throw new ArgumentNullException(nameof(handler));
  20. }
  21. public Task HandleApplicationMessageProcessedAsync(ApplicationMessageProcessedEventArgs eventArgs)
  22. {
  23. return _handler(eventArgs);
  24. }
  25. }
  26. }