In TypeScript, I am developing an API wrapper with asynchronous code to abide by the rate limit of 1 request/second set by the particular API. My goal is to create a single instantiated API wrapper that enables access to different endpoints using objects. For example, within the API there are endpoints named post
and pool
, which I aim to reach like this:
post_object.post.submit_request(argument1, ...)
or post_object.pool.submit_request(argument1, ...)
.
To maintain information across objects, I implemented an object called state_info
containing headers like user-agent, login data if provided, and a rate limiter from the Bottleneck library.
During testing, I encountered an issue where my program does not seem to be effectively limiting the request rate. Regardless of adjusting the limit in Bottleneck's arguments, requests consistently occur in about .600 seconds each time.
I suspect the problem could be related to passing around the rate limiter object or accessing it from multiple places, but I'm uncertain about the exact cause.
Here is the snippet for the Model
object representing API access:
Code snippet for Model object goes here...
And below is how I instantiate and call this class:
Code snippet for instantiation and method calls goes here...
Despite setting the minimum time between requests (mintime) to 1000 milliseconds and allowing only one concurrent request per second, the actual operation finishes much faster than anticipated, averaging half the expected duration. This discrepancy persists regardless of what value I provide for mintime
.