aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorGerhard de Clercq <[email protected]>2025-12-12 13:04:51 +0000
committerGerhard de Clercq <[email protected]>2025-12-12 15:34:57 +0000
commitb1fe9c6955ff857e3729a0bb4727247e050fb7ae (patch)
treeea6be7b3f900a4dc44b1c1a4ac104e4154cd3ec5 /embassy-executor/src
parent778bd76c1c2746ac9564132bcab0f8359feb7b13 (diff)
Add `run_until` function to std Executor as to support grafeul shutdown.
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/arch/std.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/embassy-executor/src/arch/std.rs b/embassy-executor/src/arch/std.rs
index c62ab723b..d4057144e 100644
--- a/embassy-executor/src/arch/std.rs
+++ b/embassy-executor/src/arch/std.rs
@@ -55,11 +55,24 @@ mod thread {
55 /// 55 ///
56 /// This function never returns. 56 /// This function never returns.
57 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { 57 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
58 self.run_until(init, || false);
59 unreachable!()
60 }
61
62 /// Run the executor until a flag is raised.
63 ///
64 /// This function is identical to `Executor::run()` apart from offering a `done` flag to stop execution.
65 pub fn run_until(&'static mut self, init: impl FnOnce(Spawner), mut done: impl FnMut() -> bool) {
58 init(self.inner.spawner()); 66 init(self.inner.spawner());
59 67
60 loop { 68 loop {
61 unsafe { self.inner.poll() }; 69 unsafe { self.inner.poll() };
62 self.signaler.wait() 70
71 if done() {
72 break;
73 }
74
75 self.signaler.wait();
63 } 76 }
64 } 77 }
65 } 78 }