Skip to main content

compio_actor/process_group/
strategy.rs

1use std::num::NonZeroUsize;
2
3/// Routing policy used by a process group.
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
5pub enum Strategy {
6    /// Routes each message to the member after the previous selection.
7    #[default]
8    RoundRobin,
9}
10
11impl Strategy {
12    pub(super) fn select(&self, cursor: &mut usize, members: NonZeroUsize) -> usize {
13        match self {
14            Self::RoundRobin => {
15                let selected = *cursor % members;
16                *cursor = cursor.wrapping_add(1);
17                selected
18            }
19        }
20    }
21}