tower-rs / tower

async fn(Request) -> Result<Response, Error>
https://docs.rs/tower
MIT License
3.56k stars 281 forks source link

retry: Add `Budget` trait #703

Closed boraarslan closed 2 years ago

boraarslan commented 2 years ago

This PR adds BudgetTrait and Bucket traits to allow users to implement their budget and bucket implementations. The current Budget struct is changed to be generic over Bucket. The current Bucket implementation is also renamed as TpsBucket.

A new SimpleBucket struct is added. This bucket works by increasing the cost of the next retry on each retry request. Cost is then decreased gradually on each successful request.