diff options
Diffstat (limited to 'examples/std')
| -rw-r--r-- | examples/std/src/bin/net_ppp.rs | 9 | ||||
| -rw-r--r-- | examples/std/src/bin/tick_cancel.rs | 47 |
2 files changed, 52 insertions, 4 deletions
diff --git a/examples/std/src/bin/net_ppp.rs b/examples/std/src/bin/net_ppp.rs index 82272c798..685dbf3d3 100644 --- a/examples/std/src/bin/net_ppp.rs +++ b/examples/std/src/bin/net_ppp.rs | |||
| @@ -52,7 +52,7 @@ async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: Seri | |||
| 52 | password: b"mypass", | 52 | password: b"mypass", |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | runner | 55 | let r = runner |
| 56 | .run(port, config, |ipv4| { | 56 | .run(port, config, |ipv4| { |
| 57 | let Some(addr) = ipv4.address else { | 57 | let Some(addr) = ipv4.address else { |
| 58 | warn!("PPP did not provide an IP address."); | 58 | warn!("PPP did not provide an IP address."); |
| @@ -69,9 +69,10 @@ async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: Seri | |||
| 69 | }); | 69 | }); |
| 70 | stack.set_config_v4(config); | 70 | stack.set_config_v4(config); |
| 71 | }) | 71 | }) |
| 72 | .await | 72 | .await; |
| 73 | .unwrap(); | 73 | match r { |
| 74 | unreachable!() | 74 | Err(e) => panic!("{:?}", e), |
| 75 | } | ||
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | #[embassy_executor::task] | 78 | #[embassy_executor::task] |
diff --git a/examples/std/src/bin/tick_cancel.rs b/examples/std/src/bin/tick_cancel.rs new file mode 100644 index 000000000..54e44790f --- /dev/null +++ b/examples/std/src/bin/tick_cancel.rs | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | use std::sync::atomic::{AtomicBool, Ordering}; | ||
| 2 | use std::thread; | ||
| 3 | use std::time::Duration; | ||
| 4 | |||
| 5 | use embassy_executor::Executor; | ||
| 6 | use embassy_time::Timer; | ||
| 7 | use log::*; | ||
| 8 | use static_cell::StaticCell; | ||
| 9 | |||
| 10 | #[embassy_executor::task] | ||
| 11 | async fn run() { | ||
| 12 | loop { | ||
| 13 | info!("tick"); | ||
| 14 | Timer::after_secs(1).await; | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | static DONE: StaticCell<AtomicBool> = StaticCell::new(); | ||
| 19 | static EXECUTOR: StaticCell<Executor> = StaticCell::new(); | ||
| 20 | |||
| 21 | fn main() { | ||
| 22 | env_logger::builder() | ||
| 23 | .filter_level(log::LevelFilter::Debug) | ||
| 24 | .format_timestamp_nanos() | ||
| 25 | .init(); | ||
| 26 | |||
| 27 | let done = DONE.init(AtomicBool::new(false)); | ||
| 28 | let done_cb = || done.load(Ordering::Relaxed); | ||
| 29 | |||
| 30 | let server_thread = thread::spawn(move || { | ||
| 31 | let executor = EXECUTOR.init(Executor::new()); | ||
| 32 | executor.run_until( | ||
| 33 | |spawner| { | ||
| 34 | spawner.spawn(run().unwrap()); | ||
| 35 | }, | ||
| 36 | done_cb, | ||
| 37 | ); | ||
| 38 | info!("Executor finished"); | ||
| 39 | }); | ||
| 40 | |||
| 41 | thread::sleep(Duration::from_secs(5)); | ||
| 42 | |||
| 43 | info!("Cancelling executor"); | ||
| 44 | done.store(true, Ordering::Relaxed); | ||
| 45 | |||
| 46 | server_thread.join().unwrap(); | ||
| 47 | } | ||
