Skip to main content

threads/
threads.rs

1use std::thread::scope;
2
3use bel::{Context, Program};
4
5fn main() {
6    let program = Program::compile("a + b").unwrap();
7
8    scope(|scope| {
9        scope.spawn(|| {
10            let mut context = Context::default();
11            context.add_variable("a", 1).unwrap();
12            context.add_variable("b", 2).unwrap();
13            let value = program.execute(&context).unwrap();
14            assert_eq!(value, 3.into());
15        });
16        scope.spawn(|| {
17            let mut context = Context::default();
18            context.add_variable("a", 2).unwrap();
19            context.add_variable("b", 4).unwrap();
20            let value = program.execute(&context).unwrap();
21            assert_eq!(value, 6.into());
22        });
23    });
24}