25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicationMessageProcessedHandlerDelegate.cs 1.0 KiB

12345678910111213141516171819202122232425262728293031
  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. }