embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.53k stars 768 forks source link

Feature Request: Cancel embassy executor task / `replace_spawn` #3197

Open Ddystopia opened 3 months ago

Ddystopia commented 3 months ago

Hello,

In my use case I would like to have something like embassy_executor::Spawner::replace_spawn, that will always succeed. If it cannot spawn a new task, it would cancel some already existing one.

I am sending messages to a network, and it would be easier to do replace_spawn then writing that logic inside task itself.

Gibbz commented 2 months ago

On a similar note. I found it would be handy to have access to pausing, resuming, restarting and cancelling tasks by getting a handle.

I have a project when I need to restart about 12 tasks and if I could cancel and recreate the tasks it would be much neater than having to have the same large blocks of code 12 times in each task.