From b1fe9c6955ff857e3729a0bb4727247e050fb7ae Mon Sep 17 00:00:00 2001 From: Gerhard de Clercq <11624490+Gerharddc@users.noreply.github.com> Date: Fri, 12 Dec 2025 13:04:51 +0000 Subject: Add `run_until` function to std Executor as to support grafeul shutdown. --- embassy-executor/src/arch/std.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'embassy-executor/src') 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 { /// /// This function never returns. pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! { + self.run_until(init, || false); + unreachable!() + } + + /// Run the executor until a flag is raised. + /// + /// This function is identical to `Executor::run()` apart from offering a `done` flag to stop execution. + pub fn run_until(&'static mut self, init: impl FnOnce(Spawner), mut done: impl FnMut() -> bool) { init(self.inner.spawner()); loop { unsafe { self.inner.poll() }; - self.signaler.wait() + + if done() { + break; + } + + self.signaler.wait(); } } } -- cgit