Guest User

Untitled

a guest
Feb 8th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1.  public async Task Run()
  2.         {
  3.             if (runned)
  4.                 throw new InvalidOperationException($"{nameof(TTTClient)} is already runned.");
  5.             runned = true;
  6.  
  7.             while (true)
  8.             {
  9.                 var msg = await ReciveAsync();
  10.  
  11.                 //Сюда можешь не смотреть
  12.                 if (msg is Response response)
  13.                 {
  14.                     if (requests.TryGetRequestTask(response.RequestID, out var task))
  15.                     {
  16.                         task.TrySetResult(response);
  17.                     }
  18.                 }
  19.  
  20.                 //вызов зарегистрированных обработчиков
  21.                 else
  22.                 {
  23.                     var type = msg.GetType();
  24.                     var handlers = messageHandlers.GetListeners(type);
  25.                     foreach (var item in handlers)
  26.                     {
  27.                         item(msg);
  28.                     }
  29.                 }
  30.             }
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment