title: How do I correctly use a Javascript function that has an async call in it?
body: <p>I created a Javascript function that returns a boolean value. One of the lines of code in the function invokes a REST call. I didn't realize that call was going to be asynchronous when I coded it. So, basically, the method always returns 'false' when I do something like:</p>
  
  <pre><code>if(isDataValid()) ...
  </code></pre>
  
  <p>I could move the actions in the calling function to the success function, but I was trying to create a reusable method. I'm using jQuery and Everest. I have not learned anything about Promises yet and I'm fairly new to callback programming.</p>
  
  <p>Here's boiled down version of my method:</p>
  
  <pre class="lang-js prettyprint-override"><code>function isDataValid(){
  
      // Read data from Local Storage
  
      // Create object from data
  
      // Flag variable to capture result
      var isValid = null;
  
      restClient
          .read('/my/url', model)
          .done(function(response)
              {    
                  // 'Good' response, set flag to true
                  isValid = true;
              })
          .fail(function(response)
              {   
                  // 'Bad' response, set flag to false
                  isValid = false;
              });
  
      return isValid;
  }
  </code></pre>
  
  <p>How should I make an async call and return true/false?</p>