Subject: | Calling ->count() with a negative number |
First, thank you for this module. I'm using it to implement rate limiting for sending invoices.
Second, the API is a bit akward for what I want to do. It would be nice to have an interface that would allow one to ask "I have $N tokens to process" and the answer would be "oh no, you can only do $burst of those tokens". Currently I use while ($N) { last unless $limiter->conform( 1 ); $limiter->count(1); $N--; process( $todo->[$N] ); }
Lastly, in testing I noticed it worked differently from what I expected. It starts out with an empty token bucket. Normaly this isn't a problem; in operation, the system will reach $burst by the time a batch of invoices need to be sent. But if there is a batch of pending invoices at startup, they trickle through. The solution is $limiter->count( -$burst ); This will "fill" the token bucket, but is an artifact of implementation. While this usage be deprecated at some point?