api-key-pool-0.0.1 has been yanked.
api-key-pool.rs
Pool of API keys to circumvent rate-limits.
This package provides an easy way to use multiple API keys to bypass draconian rate-limit policies.
Example
use chrono::Duration;
use tokio::time;
use api_key_pool::*;
#[tokio::main]
async fn main() {
let pol = RateLimitPolicy::new(1, Duration::seconds(2));
let api1 = APIKey::new("1", pol);
let api2 = APIKey::new("2", pol);
let api3 = APIKey::new("3", pol);
let mut pool = APIKeyPool::new();
pool.add_key(api1).await;
pool.add_key(api2).await;
pool.add_key(api3).await;
let mut ctr = 0;
while ctr < 20 {
if let Some(key) = pool.poll_for_key().await {
println!("{}", key);
ctr += 1;
} else {
println!("Have to sleep.");
time::sleep(time::Duration::from_millis(500)).await;
}
}
}