title: Mockserver: callback once request is received
body: <p>I'm using Mockserver to test an HTTP service that produces side-effects asynchronously. Let's say for example, I'm testing <code>ServiceA</code> that exposes an HTTP API method at <code>/api/status/{id}</code>. Separately from returning the status result to the caller of the API, <code>ServiceA</code> kicks off an async analysis that calls <code>ServiceB</code> if some conditions are met. Let's say this takes from a few milliseconds to a few seconds for this async process to complete.</p>
  
  <p>Currently, my mockserver code looks something like this:</p>
  
  <pre><code>Long waitTimeoutSeconds = 5L;
  Long start = System.currentTimeMillis();
  HttpRequest[] asyncRequestsRetrieved = null;
  
  while (start + (waitTimeoutSeconds * 1000L) &lt; System.currentTimeMillis()) {
      asyncRequestsRetrieved = mockServer.retrieveRecordedRequests(HttpRequest.request().withPath("/service/b/path"));
      if (asyncRequestsRetrieved != null &amp;&amp; asyncRequestsRetrieved.size &gt; 0) {
          break;
      }
      Thread.sleep(50L);
  }
  
  assertNotNull(asyncRequestsRetrieved);
  assertTrue(asyncRequestsRetrieved!!.size &gt; 0);
  </code></pre>
  
  <p>Does Mockserver expose a pattern to take an action (say, notify a listener) when a request is received at a given endpoint, or is polling my only option?</p>