title: How to block for a javascript promise and return the resolved result?
body: <p>I am obviously misunderstanding something about either the way js promises are resolved or about the semantics of "return."</p>
  
  <p>I am being called by a function that expects me to be synchronous - to return a value.  Calculating that value requires some asynchronous code (specifically, the ForEach method on a <a href="https://github.com/SitePen/dstore/blob/v1.0.0/docs/Collection.md" rel="noreferrer">dstore Collection</a> </p>
  
  <p>What I'm trying to accomplish is approximately this, but this does not work in that the function mySynchronousFunction has no return value.</p>
  
  <pre><code>function mySynchronousFunction() {
     var accumulator = {};
     var myPromise = doAsynchronousThingThatSideEffectsAccumulator();
     // Now my caller is expecting the value of accumulator.
     myPromise.then(function() {return accumulator;})
  }
  </code></pre>
  
  <p>I understand that JS has to allow for single-threaded implementations, so that it's not cool to block, but there must be some pattern for gluing asynchronous to synchronous code, that I've just missed.</p>