VDRs - Async Code Doesn't Finish Before Done is Called

When making multiple API calls from within the JavaScript in a VDR, promises and thus asynchronous calls are typically used.  To see an example of this, check out the Cloud Elements Open Labs VDR repository (async in a VDR).  Care should be taken to avoid calling `done` before the async work is complete.

An example where `done` could be called before the async code is finished: 

if (fromVendor) {
  // Some async work that takes a few seconds to complete
  // ...

  Promise.all(promises).then(() => {
    // Return once the promises are resolved
    done(transformedObject);
  });
}

// JavaScript will not wait for the above promises to resolve
done(transformedObject);

An example where `done` will not be called before the async code is finished:

if (!fromVendor) done(transformedObject);

if (fromVendor) {
  // Some async work that takes a few seconds to complete
  // ...
  Promise.all(promises).then(() => {
    // Return once the promises are resolved
    done(transformedObject);
  });
}