title: Return value from a function based on which event handler is called
body: <p>I am publishing XML messages from WebAPI to a queue using RabbitMQ (.Net client library). If the published message is successfully persisted to the disk I need to send status code 200 if not code 400 should be returned. RabbitMQ client library provides two separate events to send ACK or NACK events indicating if the message was saved or not. So my publish function needs to wait for either of the two event handles to be called before I return http response. </p>
  
  <p>How can I achieve this?</p>
  
  <p><strong>Api Controller Action</strong></p>
  
  <pre><code>[HttpPost]
  public HttpResponseMessage SendSomething()
  {
      ...
      bool success = _publisher.Publish(bytes);
      if(success) // Send status 200
      else // Send status 400
      ...
  }
  </code></pre>
  
  <p><strong>Message Publish Code</strong>   </p>
  
  <pre><code>public bool Publish(byte[] data)
  {
      ..
      channel.BasicAcks += OnAck;
      channel.BasicNacks += OnNack;
      channel.BasicPublish("", "test", null, data);
      ..
      // Depending on if OnAck or OnNack is called I need to return true or false
      return ??
  }
  
  private void OnNack(IModel model, BasicNackEventArgs args)
  {
      ...
  }
  
  private void OnAck(IModel model, BasicAckEventArgs args)
  {
      ...
  }
  </code></pre>