Skip to content

Commit

Permalink
Improve example.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Oct 25, 2023
1 parent 23e82f0 commit 2792f99
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions examples/pause_and_resume.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
//! An advanced example showing how to pause/resume/stop an `Engine` via an MPSC channel.
#[cfg(feature = "unchecked")]
fn main() {
panic!("This example does not run under 'unchecked'.");
}

use rhai::{Dynamic, Engine};

#[cfg(feature = "sync")]
use std::sync::Mutex;

#[cfg(not(feature = "unchecked"))]
fn main() {
let (tx, rx) = std::sync::mpsc::channel::<String>();

Expand Down Expand Up @@ -54,21 +60,33 @@ fn main() {
Err(_) if paused => (),
Err(_) => return None,
}

std::thread::sleep(std::time::Duration::from_millis(100));
}
});

// Run script
let _ = engine
.run(
"
r#"
let counter = 0;
loop {
print("[Script] One Potato...");
sleep(1);
counter += 1;
print("[Script] Two Potatoes...");
sleep(1);
print(`[Script] Boring Counter: ${counter}...`);
sleep(1);
print("[Script] Three Potatoes...");
sleep(1);
}
",
"#,
)
.expect_err("Error expected");

Expand Down

0 comments on commit 2792f99

Please sign in to comment.