Limit/queue calls to Google API


#1

Hello,

I am currently building a project based on Meteor. Basically the interface make several calls to the Google API. The problem is when I load the interface, all elements of the interface make simultaneous calls to the Google API, which then fails because of the rate limit of Google.

My question is how to limit the rate of these calls, or maybe queue these calls so they don’t get executed at the same time? I saw this:

https://atmospherejs.com/dandv/rate-limit

But it seems deprecated, can’t install it. Any help would be appreciated. Thanks!


#2

How about do the calls from the server in a synced call. The server method itself will be async, but your calls to Google will be nice in order.


#3

check out the _.throttle and _.debounce functions in underscore, a package required for all meteor apps.

http://underscorejs.org/#throttle

edit: if you want to set up a queue, you could attach a cache object to a wrapper around some sort of throttling mechansim. if the function is called push it onto the queue list. have the wrapper pop functions off the top of the stack, and then call them. if !stack, then dont do any thing.

basically, you could re-write that library by doing the above


#4

@mspi has the right approach to this. However, if you need additional delay between (synchronous) calls, you can make use of a timer. How many is “several”?