title: Use RxJava to dynamically run a while loop condition
body: <p>I am trying to implement a while loop across a range, similar to binary search, where I make async (with RxJava) calls in the body of the while loop.</p>
  <pre><code>while(low &lt; high) {
    int mid = (high - low) / 2
    Single&lt;Integer&gt; asyncResult = &lt;make async call using Integer mid&gt; 
    int result = asyncResult.blockingGet();
    if (result &lt; threshold) {
      low = mid;
    } else {
      high = mid;
    }
  }
  </code></pre>
  <p>This works perfectly when I make <code>blockingGet</code> calls, but if I want each body/iteration to run asynchronously, setting the <code>low</code> and <code>high</code> value gets complicated. I was able to use <code>AtomicInteger</code> for the <code>low</code> and <code>high</code> values and run it successfully using recursion, but I do not want to implement this recursively as there is a memory threshold I need to worry about.</p>
  <p>I have also tried <code>Single.repeatUntil</code> but that kicks everything off concurrently.</p>
  <p>Is there a way for me to implement the while loop conditional asynchronously based on the result of the body's asynchronous call using Flowables or someway to limit concurrency with <code>Single.repeatUntil</code>?</p>