src/js/app.js
// waitForCreation polls the api X times trying to get the ip
waitForCreation polls the api X times trying to get the ip
waitForCreation polls the api X times trying to get the ip
function waitForCreation(doClient, dropletId) {
  let deferred = $.Deferred(),
    attempts = 0;
  function poll() {
    doClient.getDroplet(dropletId)
    .done((data) => {
      let droplet = data.droplet || {};
      if (droplet.status === 'active' && droplet.networks.v4.length) {
        return deferred.resolve(data);
      }
      if (attempts >= getDropletStateMaxAttempts) {
        deferred.reject(new Error('Too many attempts'));
      }
      attempts++;
      setTimeout(poll, getDropletStatePollInterval);
    })
    .fail(deferred.reject);
  }
  poll();
  return deferred.promise();
}
function waitForCreation ( doClient , dropletId ) { let deferred = $ . Deferred ( ) , attempts = 0 ; function poll ( ) { doClient . getDroplet ( dropletId ) . done ( ( data ) => { let droplet = data . droplet || { } ; if ( droplet . status === 'active' && droplet . networks . v4 . length ) { return deferred . resolve ( data ) ; } if ( attempts >= getDropletStateMaxAttempts ) { deferred . reject ( new Error ( 'Too many attempts' ) ) ; } attempts ++ ; setTimeout ( poll , getDropletStatePollInterval ) ; } ) . fail ( deferred . reject ) ; } poll ( ) ; return deferred . promise ( ) ; }
waitForCreation polls the api X times trying to get the ip
waitForCreation polls the api X times trying to get the ip
// poll gets droplet data and if an ipv4 exists we stop, otherwise keep going // until the configured stopping point // If the request was successful check if the droplet is active. If so we // are done. If not try again. If we've hit the limit fail. // If the request fails just reject the promise // Start polling // Return a promise to try really hard or fail