I have an object that can only place 60 API calls per minute. So, what I would like to do is when a function call comes in that I know, I will not be allowed to place it, add it to the queue and call the function again at a more convenient time.
This is how I decided to fix it
var API_caller = function(){ this.function_queue = []; }; API_caller.prototype.make_api_call = function(){ if(this.can_make_call()){ this.make_call(); } else {
This works fine for functions without parameters, but what if make_api_call() had a parameter
API_caller.prototype.make_api_call = function(data){ if(this.can_make_call()){ this.make_call(); } else {
In this case, however, make_api_call(data) will be evaluated before function_queue is clicked, and func will no longer contain the function that causes the queue_call() error.
How can I get around this?
source share