Fix threading example for sync.
This commit is contained in:
parent
e902c74073
commit
2a209b82e9
@ -6,6 +6,12 @@ fn main() {
|
||||
// Channel: Master -> Script
|
||||
let (tx_master, rx_script) = std::sync::mpsc::channel();
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
let (tx_script, rx_script) = (
|
||||
std::sync::Mutex::new(tx_script),
|
||||
std::sync::Mutex::new(rx_script),
|
||||
);
|
||||
|
||||
// Spawn thread with Engine
|
||||
std::thread::spawn(move || {
|
||||
// Create Engine
|
||||
@ -13,10 +19,19 @@ fn main() {
|
||||
|
||||
// Register API
|
||||
// Notice that the API functions are blocking
|
||||
|
||||
#[cfg(not(feature = "sync"))]
|
||||
engine
|
||||
.register_fn("get", move || rx_script.recv().unwrap())
|
||||
.register_fn("put", move |v: INT| tx_script.send(v).unwrap());
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
engine
|
||||
.register_fn("get", move || rx_script.lock().unwrap().recv().unwrap())
|
||||
.register_fn("put", move |v: INT| {
|
||||
tx_script.lock().unwrap().send(v).unwrap()
|
||||
});
|
||||
|
||||
// Run script
|
||||
engine
|
||||
.consume(
|
||||
|
Loading…
Reference in New Issue
Block a user