aishek / axios-rate-limit

Rate limit for axios
MIT License
237 stars 35 forks source link

Internal setTimeout causes the application to run until the perMilliseconds time is up #32

Closed lpelorosso closed 5 months ago

lpelorosso commented 3 years ago

If you run this:

const http = rateLimit(axios.create(), { maxRequests: 4, perMilliseconds: 20000 })
http.get('http://localhost:4567/__sinatra__/404.png') 
http.get('http://localhost:4567/__sinatra__/404.png') 
http.get('http://localhost:4567/__sinatra__/404.png') 

It will perform the three requests, and then the application will continue running for 20 seconds until the internal timeout is up.

aishek commented 5 months ago

This is correct. It is expected behavior by design.

It could be better. And https://github.com/aishek/axios-rate-limit/pull/39/files solves the problem. I think about adopting the algorithm from there in future versions.