title: Promise - try until it succeds
body: <p>I'm using native node.js's Promises and the question <a href="https://stackoverflow.com/questions/26694467/promises-repeat-operation-until-it-succeeds">here</a> did give me any point.
  Basically, I have a function like below:</p>
  
  <pre><code>var foo = foo (resolve, reject) {
      return obj
          .doA()
          .doB()
          .then(function (value) {
              // here I choose if I want to resolve or reject.
          })
          .catch(function(err) {
          });
  }
  
  var promise = new Promise(foo);
  
  return promise
      .then(function() {
          // I know here what I have to return.
      })
      .catch(function(err){
          // I want to repeat the foo function until it is resolved and not rejected. 
      })
  </code></pre>
  
  <p><code>obj</code> is a promised object. I would to like to retry the foo function as long as the promise is fulfilled; if it's rejected, then try again.</p>
  
  <p>I do not know how to structure the chain. Any help?
  Thanks.</p>