pub trait RotationStrategy:
Send
+ Sync
+ 'static {
// Required method
fn select<'a, 'life0, 'async_trait>(
&'life0 self,
candidates: &'a [ProxyCandidate],
) -> Pin<Box<dyn Future<Output = ProxyResult<&'a ProxyCandidate>> + Send + 'async_trait>>
where Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait;
}Expand description
Selects a proxy from a slice of candidates on each request.
Implementations receive all candidates (healthy and unhealthy) so they
can distinguish between an empty pool and a pool where every proxy is
temporarily down. Call healthy_candidates to filter the slice.
§Example
use stygian_proxy::strategy::{ProxyCandidate, RotationStrategy, RoundRobinStrategy};
async fn pick(candidates: &[ProxyCandidate]) {
let strategy = RoundRobinStrategy::default();
let chosen = strategy.select(candidates).await.unwrap();
println!("selected: {}", chosen.id);
}Required Methods§
Sourcefn select<'a, 'life0, 'async_trait>(
&'life0 self,
candidates: &'a [ProxyCandidate],
) -> Pin<Box<dyn Future<Output = ProxyResult<&'a ProxyCandidate>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn select<'a, 'life0, 'async_trait>(
&'life0 self,
candidates: &'a [ProxyCandidate],
) -> Pin<Box<dyn Future<Output = ProxyResult<&'a ProxyCandidate>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Select one candidate from candidates.
Returns crate::error::ProxyError::AllProxiesUnhealthy when every candidate has
healthy == false.