title: Java 8 - retry a method until a condition is fulfilled (in intervals)
body: <p>I want to create a class that can run a method until a condition about the return value is fulfilled.   </p>
  
  <p>It should look something like this </p>
  
  <pre><code>methodPoller.poll(pollDurationSec, pollIntervalMillis)
              .method(dog.bark())
              .until(dog -&gt; dog.bark().equals("Woof"))
              .execute();
  </code></pre>
  
  <p>My method poller look somewhat like this () // following GuiSim answer</p>
  
  <pre><code>public class MethodPoller {
      Duration pollDurationSec;
      int pollIntervalMillis;
  
  
      public MethodPoller() {
      }
  
      public MethodPoller poll(Duration pollDurationSec, int pollIntervalMillis) {
          this.pollDurationSec = pollDurationSec;
          this.pollIntervalMillis = pollIntervalMillis;
          return this;
      }
  
      public &lt;T&gt; MethodPoller method(Supplier&lt;T&gt; supplier) {
  
          return this;
      }
  
      public &lt;T&gt; MethodPoller until(Predicate&lt;T&gt; predicate) {
  
          return this;
      }
  }
  </code></pre>
  
  <p>But I am having a hard time going opn from here.<br>
  How can I implement a retry to a general method until a condition is fulfilled?<br>
  Thanks.</p>