title: Spring Reactor Flux, how to subscribe and later block until all done
body: <p>Spring reactor provides blocklast() if I want to be synchronous and block until all elements are done</p>
  <p>But what if I want to continue a bit and then block until all elements are done?</p>
  <p>( I do not want to perform a busy wait using isDisposed )</p>
  <p>Do I need to do it myself with my own signal triggered by onComplete, or is there a better built in API?</p>
  <pre><code>//reactor provides blocklast if I want to be synchronous and block until all elements are done
  //Integer data = Flux.range(1,10).delayElements(Duration.ofSeconds(1)).doOnNext((Integer next) -&gt; System.out.println(next + &quot; on thread &quot; + Thread.currentThread().getName())).blockLast();
   
  //but what if I want to continue a bit and then block
  //do I need to do it myself like this? is there a better way?
  Object signal = new Object(); 
  Flux.range(1,10).delayElements(Duration.ofSeconds(1)).doOnNext((Integer next) -&gt; System.out.println(next + &quot; on thread &quot; + Thread.currentThread().getName())).doOnComplete(()-&gt;{synchronized(signal) { signal.notify();}}).subscribe();
  // do some other work here, then wait for done
  synchronized (signal) {
      signal.wait();
  }
  System.out.println(&quot;All done&quot;);
  </code></pre>