title: Making asynchronous API synchronous
body: <p>I am connecting to an API to get some data that is defined like this:</p>
  
  <p>A client object <code>ClientConnection</code>, which allows one to send requests.
  A IApi interface that needs to be passed to  the <code>ClientConnection</code> to receive callbacks.
  Schematically it looks like this:</p>
  
  <pre><code>// defined in the API dll
  public class ClientConnection {
      public ClientConnection(IApi api) { ... }
      public void request(int reqid, string reqdetails) { ... }
  }
  
  interface IApi
  {
      void receiveData(int reqid, string ans);
  }
  </code></pre>
  
  <p>Now, obviously this is a fairly standard asynchronous way of doing things: send requests through a global object, with a requestid, and receive answers tagged with that requestid.</p>
  
  <p>I want to create a wrapper that is synchronous. What would be the most natural way of doing this? Is there a smart way of using async await, instead of using thread locking and stuff?</p>
  
  <pre><code>class MyWrapper : IApi
  {
      private ClientConnection _client;
      private int _reqToken = 0;
      public MyWrapper()
      {
          _client = new ClientConnection(this);
      }
  
      public string getData(string reqdetails)
      {
          _client.request(_reqToken++, reqdetails);
          // what to do here?
      }
  
      public void receiveData(int reqid, string data) {
          // what to do here?
      }
  }
  </code></pre>