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