title: While loop with A+ promises in JavaScript / node.js
body: <p>I need to keep calling remote API until I get the response I need, and I would like to use the Official A+ promises in node.js.  Sync psudo code:</p>
  
  <pre><code>params = { remote api call params }
  while (true) {
      result = callRemoteApi(params)
      if isGood(result) {
          onSuccess(result)
          break
      }
      params = modify(params)
  }
  </code></pre>
  
  <p>I am using the <a href="https://www.npmjs.com/package/request-promise" rel="nofollow noreferrer">request-promise</a> lib for requests, so the result might be something like this:</p>
  
  <pre><code>new Promise(function (resolve, reject) {
      var task = request({params})
          .then(function (result) {
              if (isGood(result)) {
                  resolve(result);
              } else {
                  task = request({new params}).then(this_function);
              }
          });
  </code></pre>
  
  <p>P.S. This is very similar to <a href="https://stackoverflow.com/a/17238793/177275">https://stackoverflow.com/a/17238793/177275</a>, but I would like a non-q-based implementation.</p>