|
1 | | -// Test basic DAG function syntax |
2 | | -// run-pass |
3 | 1 |
|
4 | | -// DAG function that defines tasks and their dependencies |
5 | | -dag fn simple_dag() { |
6 | | - // Define tasks |
| 2 | +dag fn pipeline_dag() { |
| 3 | + task fetch_data { |
| 4 | + println!("Fetching data..."); |
| 5 | + } |
| 6 | + |
| 7 | + task process_data { |
| 8 | + println!("Processing data..."); |
| 9 | + } |
| 10 | + |
| 11 | + task save_result { |
| 12 | + println!("Saving result..."); |
| 13 | + } |
| 14 | + edge fetch_data -> process_data; |
| 15 | + edge process_data -> save_result; |
| 16 | +} |
| 17 | + |
| 18 | +dag fn parallel_dag() { |
7 | 19 | task A { |
8 | | - println!("Executing task A"); |
| 20 | + println!("Task A - start"); |
| 21 | + std::thread::sleep(std::time::Duration::from_millis(100)); |
| 22 | + println!("Task A - end"); |
9 | 23 | } |
10 | 24 |
|
11 | 25 | task B { |
12 | | - println!("Executing task B"); |
| 26 | + println!("Task B - start"); |
| 27 | + std::thread::sleep(std::time::Duration::from_millis(100)); |
| 28 | + println!("Task B - end"); |
13 | 29 | } |
14 | 30 |
|
15 | 31 | task C { |
16 | | - println!("Executing task C"); |
| 32 | + println!("Task C - start"); |
| 33 | + std::thread::sleep(std::time::Duration::from_millis(100)); |
| 34 | + println!("Task C - end"); |
17 | 35 | } |
18 | 36 |
|
19 | | - // Define dependencies (edges) |
20 | | - // A -> B means B depends on A (A must run before B) |
| 37 | + task D { |
| 38 | + println!("Task D - depends on B and C"); |
| 39 | + } |
21 | 40 | edge A -> B; |
22 | 41 | edge A -> C; |
23 | | - edge B -> C; |
| 42 | + edge B -> D; |
| 43 | + edge C -> D; |
| 44 | +} |
| 45 | + |
| 46 | +dag fn task_a(x: i32) -> i32 { |
| 47 | + println!("Executing task A with x = {}", x); |
| 48 | + x * 2 |
| 49 | +} |
| 50 | + |
| 51 | +dag fn task_b(y: i32, z: i32) -> i32 { |
| 52 | + println!("Executing task B with y = {}, z = {}", y, z); |
| 53 | + y + z |
| 54 | +} |
| 55 | + |
| 56 | +dag fn task_c(result: i32) { |
| 57 | + println!("Executing task C with result = {}", result); |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +fn test_keywords_as_variables() { |
| 62 | + |
| 63 | + let edge = 42; |
| 64 | + println!("edge = {}", edge); |
| 65 | + |
| 66 | + |
| 67 | + let task = "hello"; |
| 68 | + println!("task = {}", task); |
| 69 | + |
| 70 | + |
| 71 | + let dag = vec![1, 2, 3]; |
| 72 | + println!("dag = {:?}", dag); |
24 | 73 | } |
25 | 74 |
|
26 | 75 | fn main() { |
27 | | - // Call the DAG function |
28 | | - simple_dag(); |
29 | | - println!("DAG execution completed!"); |
| 76 | + println!("=== Style 1: DAG with internal tasks ==="); |
| 77 | + pipeline_dag(); |
| 78 | + parallel_dag(); |
| 79 | + println!("\n=== Style 2: Chaining dag functions with edge ==="); |
| 80 | + edge task_a(10) -> task_b(_, 30); |
| 81 | + edge task_b(20, 30) -> task_c(_); |
| 82 | + |
| 83 | + println!("\n=== Test keywords as variables ==="); |
| 84 | + test_keywords_as_variables(); |
| 85 | + |
| 86 | + println!("\nDAG execution completed!"); |
30 | 87 | } |
0 commit comments