use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub enum DispatchStrategy {
#[default]
RoundRobin,
LeastLoaded,
}
#[derive(Clone)]
pub struct RoundRobinDispatcher {
counter: Arc<AtomicUsize>,
slots: usize,
}
impl RoundRobinDispatcher {
pub fn new(slots: usize) -> Self {
Self {
counter: Arc::new(AtomicUsize::new(0)),
slots,
}
}
pub fn next(&self) -> usize {
if self.slots == 0 {
return 0;
}
self.counter.fetch_add(1, Ordering::Relaxed) % self.slots
}
}