aboutsummaryrefslogtreecommitdiff
path: root/examples/std
diff options
context:
space:
mode:
authorRaul Alimbekov <[email protected]>2025-12-16 09:05:22 +0300
committerGitHub <[email protected]>2025-12-16 09:05:22 +0300
commitc9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch)
tree6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /examples/std
parentcde24a3ef1117653ba5ed4184102b33f745782fb (diff)
parent5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff)
Merge branch 'main' into main
Diffstat (limited to 'examples/std')
-rw-r--r--examples/std/Cargo.toml2
-rw-r--r--examples/std/src/bin/net_ppp.rs9
-rw-r--r--examples/std/src/bin/tick_cancel.rs47
3 files changed, 53 insertions, 5 deletions
diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml
index 449c5ddca..6dc6a353d 100644
--- a/examples/std/Cargo.toml
+++ b/examples/std/Cargo.toml
@@ -1,5 +1,5 @@
1[package] 1[package]
2edition = "2021" 2edition = "2024"
3name = "embassy-std-examples" 3name = "embassy-std-examples"
4version = "0.1.0" 4version = "0.1.0"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
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 @@
1use std::sync::atomic::{AtomicBool, Ordering};
2use std::thread;
3use std::time::Duration;
4
5use embassy_executor::Executor;
6use embassy_time::Timer;
7use log::*;
8use static_cell::StaticCell;
9
10#[embassy_executor::task]
11async fn run() {
12 loop {
13 info!("tick");
14 Timer::after_secs(1).await;
15 }
16}
17
18static DONE: StaticCell<AtomicBool> = StaticCell::new();
19static EXECUTOR: StaticCell<Executor> = StaticCell::new();
20
21fn 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}