Managing Asynchronous Function Calls
There will be many times where one will encounter calling a function to a database or 3rd-party API service several times and that order of execution must remain intact.
For the example below, we are calling the gmail email sending function that is asynchronous with a callback function. Using a for loop will fail because of the non-blocking nature of the call. The sending function will not utilize the proper index of the array that is to be executed upon.
A better working approach is to use recursion with the index locked into the callback function. This in turn creates a blocking effect where the function only executes the array of elements it is provided in a serial and ordered procedure.