bandwidth-throttle / token-bucket

Implementation of the Token Bucket algorithm in PHP.
Do What The F*ck You Want To Public License
503 stars 77 forks source link

Feature request: refund tokens #25

Closed yuchanns closed 2 years ago

yuchanns commented 4 years ago

Thanks for such a nice pkg! I wonder if there is any method like refund or something that can return the tokens to the bucket.

I used this feature mainly for trade amount limitation. In such a case:

// ...
// consume when an order creating.
$bucket->consume($order->total);
$order->create();
// then order turns to failed.
$order->failed();
$bucket->refund($order->total);

For now I implement this feature on my own. But I think that would be better if there is official support :)