use std::sync::atomic::{AtomicUsize, Ordering};
pub struct EnginePool {
urls: Vec<String>,
idx: AtomicUsize,
}
impl EnginePool {
pub fn new(urls: Vec<String>) -> Self {
Self {
urls,
idx: AtomicUsize::new(0),
}
}
pub fn next_url(&self) -> Option<String> {
let len = self.urls.len();
if len == 0 {
return None;
}
let i = self.idx.fetch_add(1, Ordering::Relaxed) % len;
Some(self.urls[i].clone())
}
}