forked from cel-rust/cel-rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreads.rs
More file actions
23 lines (21 loc) · 743 Bytes
/
threads.rs
File metadata and controls
23 lines (21 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use cel_interpreter::{Context, Program};
use std::thread::scope;
fn main() {
let program = Program::compile("a + b").unwrap();
scope(|scope| {
scope.spawn(|| {
let mut context = Context::default();
context.add_variable("a", 1).unwrap();
context.add_variable("b", 2).unwrap();
let value = program.execute(&context).unwrap();
assert_eq!(value, 3.into());
});
scope.spawn(|| {
let mut context = Context::default();
context.add_variable("a", 2).unwrap();
context.add_variable("b", 4).unwrap();
let value = program.execute(&context).unwrap();
assert_eq!(value, 6.into());
});
});
}