deckar01 / ratelimit

API Rate Limit Decorator
MIT License
20 stars 2 forks source link

Optimize Sleep Time for Multiple Limits #2

Open deckar01 opened 4 years ago

deckar01 commented 4 years ago

Chaining limits causes waiting processes to wake early and churn.

deckar01 commented 4 years ago

The RateLimitDecorator could inspect the func in __call__ and determine if it is a compatible wrapper with attributes like __func__ and __limits__. It could then discard the previously wrapped func, wrap the original __func__, and append the previous __limits__ to its own instance. Then sleep time can be computed as the maximum period remaining of all limits.