title: How can I serve a "resolve" in my recursive AJAX calls so that I can use 'done'?
body: <p>I am doing a few recurring AJAX calls where I pass an array from the front-end to the back-end and whenever it comes back to the front-end, the array gets smaller (by 1) and ultimately it'll be empty, therefore my recursive calls will stop.</p>
  
  <p>Here's my calls:</p>
  
  <pre><code>function download_required_files(demo_data) {
      var ajaxsecurity = setup_page_params.ajax_nonce;
  
      jQuery.ajax({
          url: ajaxurl,
          type: 'POST',
          dataType: 'json',
          data: {
              action: 'download_import_files_request',
              security: ajaxsecurity,
              content_install_request_data: JSON.stringify(demo_data),
          },
  
          success: function (response) {
              console.log(response);
              var data = response.data || false;
              /**
               * If no steps are left, meaning that all required files have been downloaded, proceed with the whole install process.
               */
              if(!data.remaining_steps || !data.remaining_steps.length) {
                  return false;
              }
  
              if(data.can_continue !== 'yes') {
                  return false;
              }
  
              if(data.remaining_steps &amp;&amp; data.remaining_steps.length) {
                  demo_data.steps_to_take = data.remaining_steps;
                  download_required_files(demo_data);
  
              }
  
              $('.demo-loader-content').fadeOut();
          },
  
          error: function (response) {
              $('.demo-loader-content').fadeOut();
  
          }
      });
  }
  </code></pre>
  
  <p>Assuming I have 2 steps to download files for, this <code>download_required_files</code> will run twice, then it'll be done, but if I do:</p>
  
  <pre><code>var download_process = download_required_files(demo_data) //Runs 2 times
  download_process.done(function() {  //Do stuff here once that function ran 2 times });
  </code></pre>
  
  <p>It gives me the: <code>Cannot read property 'done' of undefined</code> error and for good reason. That <code>download_process</code> is not a promise object for it to have that property, it's just...empty.</p>
  
  <p>Where should I intervene in my <code>download_required_files</code> so that it signals to outside code that "Hey, in a promise environment, I'm done!"?</p>