dag_scheduler/
lib.rs

1// pub mod scheduler;
2pub mod nodes;
3pub mod pipeline;
4pub mod utils;
5
6// #[cfg(test)]
7// mod tests {
8//     use std::thread;
9
10//     use crossbeam::channel::{Receiver, Sender};
11
12//     use crate::nodes::CommonNode;
13
14//     use super::*;
15
16//     #[test]
17//     fn test_pipeline() {
18//         struct CtxV {
19//             pub a: i32
20//         }
21
22//         fn init(_: Vec<Receiver<CtxV>>, outputs: Vec<Sender<CtxV>>) {
23//             for _ in 0..10000 {
24//                 outputs[0].send(CtxV { a: 1 }).unwrap();
25//             }
26//         }
27
28//         fn add_one(inputs: Vec<Receiver<CtxV>>, outputs: Vec<Sender<CtxV>>)  {
29//             for mut ctx in inputs[0].iter() {
30//                 ctx.a += 1;
31//                 outputs[0].send(ctx).unwrap();
32//             }
33//         }
34
35//         fn add_two(inputs: Vec<Receiver<CtxV>>, outputs: Vec<Sender<CtxV>>)  {
36//             for mut ctx in inputs[0].iter() {
37//                 ctx.a += 2;
38//                 outputs[0].send(ctx).unwrap();
39//             }
40//         }
41
42//         let mut sche = scheduler::Scheduler::new();
43
44//         sche.add_node(false, &vec![], Box::new(CommonNode::new("first", 2, &[10], init)));
45//         sche.add_node(false, &vec![("first", 0)], Box::new(CommonNode::new("second", 2, &[10], add_one)));
46//         let outputs = sche.add_node(true, &vec![("second", 0)], Box::new(CommonNode::new("third", 2, &[10], add_two))).unwrap();
47
48//         let handler = thread::spawn(move|| {
49//             let mut result = vec![];
50//             for ctx in outputs[0].iter() {
51//                 result.push(ctx.a);
52//             }
53//             return result;
54//         });
55
56//         sche.start();
57//         let result = handler.join().unwrap();
58//         println!("result:{result:?}");
59
60//     }
61
62//     #[test]
63//     fn test_lined_printer() {
64//         println!("a");
65//         println!("b");
66//         println!("c");
67//         print!("\x1b[3A\x1b[K");
68//         println!("A");
69//         println!("B");
70//         println!("C");
71
72//     }
73// }