Skip to main content

bamboo_domain/session/composition/
parallel.rs

1//! Parallel execution strategies.
2
3use serde::{Deserialize, Serialize};
4
5/// Controls how parallel branches should be waited for.
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
7#[serde(rename_all = "snake_case")]
8#[derive(Default)]
9pub enum ParallelWait {
10    /// Wait for all branches to complete
11    #[default]
12    All,
13    /// Wait for any branch to complete (first to finish)
14    Any,
15    /// Wait for at least N branches to complete
16    N(usize),
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn test_parallel_wait_serialization() {
25        let all = ParallelWait::All;
26        let json = serde_json::to_string(&all).unwrap();
27        assert!(json.contains("\"all\""));
28
29        let any = ParallelWait::Any;
30        let json = serde_json::to_string(&any).unwrap();
31        assert!(json.contains("\"any\""));
32
33        let n = ParallelWait::N(3);
34        let json = serde_json::to_string(&n).unwrap();
35        assert!(json.contains("\"N\":3") || json.contains("\"n\":3"));
36    }
37
38    #[test]
39    fn test_parallel_wait_roundtrip() {
40        let variants = vec![ParallelWait::All, ParallelWait::Any, ParallelWait::N(3)];
41        for original in variants {
42            let json = serde_json::to_string(&original).unwrap();
43            let deserialized: ParallelWait = serde_json::from_str(&json).unwrap();
44            assert_eq!(original, deserialized);
45        }
46    }
47}