title: SignalR "server" await to SignalR Client
body: <p>I am currently building a .NET Core WebAPI with a SignalR hub that is sending requests to one or more SignalR clients.</p>
  <p>At this point, I need to send a request to a SignalR client and wait for it to return the information, but wait within the same method that sent the request to the client, something like this:</p>
  <pre class="lang-cs prettyprint-override"><code>public async Task&lt;MyObject&gt; GetItemStock() {
      await _myHubSignalR.Clients.Client(connectionId).SendAsync(&quot;MethodMessage&quot;, &quot;ItemStockByItemId-001|pendingProcessId=34243243242342&quot;);
      // ^ I want await here until received the stock of itemId 001
  }
  </code></pre>
  <p>The only way I found (and there must be a gap in my understanding, hence asking for your help) is something like this:</p>
  <ul>
  <li>The hub sends an order to the customer;</li>
  <li>The SignalR client, when receiving a post, makes a different method call;</li>
  <li>I define a maximum waiting time in the WebApi method;</li>
  <li>Within this method, I am constantly querying the database to see if it has new information.</li>
  </ul>
  <p>However, I think the way I managed to get around is not good.</p>
  <pre class="lang-cs prettyprint-override"><code>public async Task&lt;MyObject&gt; GetItemStock() {
      await _myHubSignalR.Clients.Client(connectionId).SendAsync(&quot;MethodMessage&quot;, &quot;ItemStockByItemId-001|pendingProcessId=34243243242342&quot;);
              
      int awaitSeconds = 20000;
      int maxWait = 0;
      bool continueAwait = true;
      string result = &quot;&quot;;
      while (continueAwait) {
              maxWait += 3000;
              Thread.Sleep(3000);
              result = await Task.Run(() =&gt; {
                  return myProvider.SeeHasNewDataOnDataBase(pendingProcessId);
              });
  
          if (result != &quot;&quot; || maxWait &gt; awaitSeconds) {
              myProvider.DeletePreviusDataFromDataBase(pendingProcessId);
              return result;
          }
      }
  </code></pre>
  <p>The idea was to use the method that sends the request to the SignalR client, and in this same method obtain the information that the SignalR client sent or will send.</p>