您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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