jhurliman/node-rate-limiter

No way to calculate amount of time until the next drip?

KevinNovak opened this issue · 0 comments

I am using this package to create cooldowns for certain commands that users run, and I want to be able to tell the user the amount of time they have to wait until they can run the command again.

I can't seem to find any way that this is possible with the current code.

We can get:

  • The time of the last drip with myLimiter.tokenBucket.lastDrip
  • We can then calculate the next drip time based on the last drip time + the interval length

But there does not seem to be a way to tell what the current time within an interval is. Therefore I cannot calculate how much time is left before the next drip.

EDIT: It seems like this could be solved by giving us access to the internal clock, specifically getMilliseconds(). Additionally, maybe we could have a method to getTimeToNextDrip() or getTimeToNextInterval()?