I am obviously misunderstanding something about either the way js promises are resolved or about the semantics of "return."
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 dstore Collection
What I'm trying to accomplish is approximately this, but this does not work in that the function mySynchronousFunction has no return value.
function mySynchronousFunction() {
var accumulator = {};
var myPromise = doAsynchronousThingThatSideEffectsAccumulator();
// Now my caller is expecting the value of accumulator.
myPromise.then(function() {return accumulator;})
}
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.