futures-rate
What is this library
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.
How to use
Installation
First of all, add the dependency to your Rust project:
Or in your project's Cargo.toml
, add the following dependency:
[]
= "^0.1.0"
then run $ cargo install
in your terminal from project's root directory.
Limit access rate
- Create and manage a
GateKeeper
object in your main thread, which will set the access limit to a certain resource:
use GateKeeper;
/// then in main thread
- Then register your future to the
GateKeeper
such that the resourceful future can be protected:
use ;
/// in the business logic which has access to the `gatekeeper` object
async
Naive Future Lock
If setting the
Examples
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.
use ;
use ;
use Future;
use thread;
use Duration;