title: Loading remote data, caching, and continuing in javascript
body: <p>Basic use case. I have a global variable where I store remotely pulled data. If there is no data then I want to load it initially, wait for it load, and then continue processing. I don't really want to use a synchronous process if I don't have to.</p>
  
  <p>Consider something like this where _companies is a global variable...</p>
  
  <pre><code>    if (_companies === undefined || _companies.length == 0) {
         loadExternalData();
      }
      // do something with the data in _companies
  </code></pre>
  
  <p>I feel like I'm missing something obvious. I understand that I can call async = false but that seems like a cludge. I could also put all the code in the  block in a function, make an if..else and then call the function from loadExternalData() as well as in my else statement but again that seems like a cludge. It seems like I should be able to wrap that entire thing in a callback but I don't know how to do that.</p>