| 444 | |
| 445 | #[test] |
| 446 | fn run_fn_captures_mutable_state() { |
| 447 | // Proves the RunFn / context model supports shared mutable |
| 448 | // data between passes — the real engine use case is writing |
| 449 | // to the encoder or the profiler. |
| 450 | let counter = Arc::new(Mutex::new(0)); |
| 451 | let c1 = counter.clone(); |
| 452 | let c2 = counter.clone(); |
| 453 | |
| 454 | let mut graph: Graph<'_, TestCtx> = Graph::new(); |
| 455 | graph.push(PassNode::new("a", Box::new(move |_ctx| { |
| 456 | *c1.lock().unwrap() += 1; |
| 457 | }))); |
| 458 | graph.push(PassNode::new("b", Box::new(move |_ctx| { |
| 459 | *c2.lock().unwrap() += 10; |
| 460 | }))); |
| 461 | let mut ctx = Vec::new(); |
| 462 | graph.execute(&mut ctx).unwrap(); |
| 463 | assert_eq!(*counter.lock().unwrap(), 11); |
| 464 | } |
| 465 | } |