title: Recursive Promise Call- Memory Scope Variable Issue
body: <p>I have these functions for the purpose of retrieving a token through a api call out. If the user enters the wrong password, the promise will reject and on reject the function is called again to give the user another try. </p>
  
  <p>If the user enters the right password the first time, there is no issue. </p>
  
  <p>But if the user enters a wrong password and tries again...but tries again successfully, I am having a memory issue. Because of the recursive call to <code>callApiToken()</code> on the second try the promise is fullfilled and  <code>callApiToken().then(function() { refreshToken(); })</code> is called.  <code>file.token = JSON.parse(tokenString);</code> is completed but in a different memory scope. Not sure what to do about this. I say this because the routine runs successfully. But the global <code>var file</code> is not populated as it should be. </p>
  
  <p><code>createTokenFile()</code> is called first. </p>
  
  <pre><code>var file = {};
  
  function createTokenFile() {
      block = true;
      callApiToken()
          .then(function() { refreshToken(); }) // ON THE SECOND RECURSIVE     
          .catch(function() {                  // RUN refreshToken() IS CALLED
              callApiToken();
          }).finally(function() {
              block = false;
          });
  }
  
  function refreshToken() {
      var tokenFileAbsolute = path.join(__dirname, 'token-file.json');
      return fs.readFileAsync(tokenFileAbsolute, {encoding: 'utf-8'})
          .then(function(tokenString) {
              file.token = JSON.parse(tokenString);
          }).catch(function(err) {
              console.log("No token-file.json file found. " .red +
                  "Please complete for a new one." .red);
              createTokenFile();
          });
  }
  </code></pre>
  
  <p><strong>UPDATE</strong> with other promise code that gives resolve for <code>callApiToken()</code>which is actually <code>getCredentials</code>:</p>
  
  <p>Note: <code>fs.writeFileAsync(tokenFile, token)</code> does complete successfully on the second recursive call.</p>
  
  <pre><code>function getPassword(user) {
      return readAsync({prompt: "Password: ", silent: true, replace: "*" })
          .then(function(pass) {
              return postAsync(URL, payload(user[0], pass[0]));
          });
  }
  function getCredentials() {
      return readAsync({prompt: "Username: "}).then(getPassword);
  }
  
  function writeToFile(data, response) {
      tokenFile =  path.join(__dirname, 'token-file.json');
      token = JSON.stringify({
          id: data.access.token.id,
          expires: data.access.token.expires
      });
      return fs.writeFileAsync(tokenFile, token).then(function(err) {
          if (err) throw err;
          console.log("Token was successfully retrieved and written to " .cyan +
              tokenFile .cyan + "." .cyan);
       });
  }
  </code></pre>