How to limit the function to only 10 times per second, but continue execution when new spots are available? This means that we will call the function 10 times as soon as possible, and when 1 second has passed since the call of any function, we can make another call.
This description may be misleading, but the answer will be the fastest way to complete the X API call numbers given the speed limit.
Example: Here is an example that iterates over the alphabet to print each letter. How can we limit this to only printLetter 10 times per second? I still want to sort through all the letters, only with the appropriate speed.
function printLetter(letter){ console.log(letter); } var alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "Y", "Z"]; // How can I limit this to only run 10 times per second, still loop through every letter, and complete as fast as possible (ie not add a hard spacing of 100ms)? alphabet.forEach(function(letter){ printLetter(letter); });
Edit: Please do not answer in downvote format without leaving comments, explaining why this is a bad answer.
Edit 2: A good solution would not block every call for 100 ms. This makes the minimum run time of 1 second for 10 calls - when you could actually do this (almost) at the same time and potentially complete in a split second.