title: Project Reactor: wait while broadcaster finish
body: <p>There is a Broadcaster, that accepts strings and append them to a StringBuilder.</p>
  
  <p>I want to test it.</p>
  
  <p>I have to use <code>Thread#sleep</code> to wait, while the broadcaster finish processing of strings. I want to remove <code>sleep</code>.</p>
  
  <p>I tried to use <code>Control#debug()</code> unsuccessfully. </p>
  
  <pre><code>public class BroadcasterUnitTest {
  
  @Test
  public void test() {
      //prepare
      Environment.initialize();
      Broadcaster&lt;String&gt; sink = Broadcaster.create(Environment.newDispatcher()); //run broadcaster in separate thread (dispatcher)
      StringBuilder sb = new StringBuilder();
      sink
              .observe(s -&gt; sleep(100)) //long-time operation
              .consume(sb::append);
  
      //do
      sink.onNext("a");
      sink.onNext("b");
  
      //assert
      sleep(500);//wait while broadcaster finished (if comment this line then the test will fail)
      assertEquals("ab", sb.toString());
  }
  
  private void sleep(int millis) {
      try {
          Thread.sleep(millis);
      } catch (InterruptedException e) {
          throw new RuntimeException(e);
      }
  }
  }
  </code></pre>