futures-rate

This library provides easy tools to help Rust applications guide critical resources or code paths from being overwhelmed.

Depending on the configuration, the library will limit the amount of guarded futures being polled concurrently.

Example

A classic use case is to place a [GateKeeper] over an a client socket pool, such that only a limited number of future visitors can be allowed to poll the resources and hence limit the amount of open connections.

```rust use futures::{executor, future}; use futures_rate::{GateKeeper, Permit}; use std::future::Future; use std::thread; use std::time::Duration;

fn main() { let gatekeeper = GateKeeper::new(1); let futvalues = async { let fut1 = buildfut(0, &gatekeeper); let fut2 = buildfut(1, &gatekeeper); let fin = future::join(fut1, fut_2); fin.await };

 let values = executor::block_on(fut_values);

 println!("Values from fut_1={:?}", values.0);
 println!("Values from fut_2={:?}", values.1);

}

fn buildfut( offset: i32, gatekeeper: &GateKeeper, ) -> Permit, impl Future>> { gatekeeper.register(async move { let mut values = Vec::withcapacity(100); (0..100).foreach(|v| { thread::sleep(Duration::frommillis(1)); values.push(2 * v + offset); });

     values
 }).unwrap()

} ```