My node4 lambda function called via API GW makes a sequence of slow API calls.
In order to not let users wait until everything completes, I'm planning to have my code look like this:
function(event, context, callback) {
...
// Return users API GW call now
callback(null, data);
// Do the heavy lifting afterwards.
longApiCall().then(otherLongApiCalls)
}
But now I read in the AWS docs:
"the callback will wait until the Node.js runtime event loop is empty before freezing the process and returning the results to the caller"
Does that mean the API GW returns the response data before or after the longApiCalls complete?
If after, is there a suggested way for how to "return early" before everything is finished?