From 3d97c9e431d7fcb20b1b30bc15c34ccffee03c79 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 22 Apr 2023 21:27:26 +0200 Subject: Move deprecated migration guides to deprecated folder --- book/en/src/migration_v1_v2/async_tasks.md | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 book/en/src/migration_v1_v2/async_tasks.md (limited to 'book/en/src/migration_v1_v2/async_tasks.md') diff --git a/book/en/src/migration_v1_v2/async_tasks.md b/book/en/src/migration_v1_v2/async_tasks.md new file mode 100644 index 0000000..54e0893 --- /dev/null +++ b/book/en/src/migration_v1_v2/async_tasks.md @@ -0,0 +1,55 @@ +# Using `async` softare tasks. + +There have been a few changes to software tasks. They are outlined below. + +### Software tasks must now be `async`. + +All software tasks are now required to be `async`. + +#### Required changes. + +All of the tasks in your project that do not bind to an interrupt must now be an `async fn`. For example: + +``` rust +#[task( + local = [ some_resource ], + shared = [ my_shared_resource ], + priority = 2 +)] +fn my_task(cx: my_task::Context) { + cx.local.some_resource.do_trick(); + cx.shared.my_shared_resource.lock(|s| s.do_shared_thing()); +} +``` + +becomes + +``` rust +#[task( + local = [ some_resource ], + shared = [ my_shared_resource ], + priority = 2 +)] +async fn my_task(cx: my_task::Context) { + cx.local.some_resource.do_trick(); + cx.shared.my_shared_resource.lock(|s| s.do_shared_thing()); +} +``` + +## Software tasks may now run forever + +The new `async` software tasks are allowed to run forever, on one precondition: **there must be an `await` within the infinite loop of the task**. An example of such a task: + +``` rust +#[task(local = [ my_channel ] )] +async fn my_task_that_runs_forever(cx: my_task_that_runs_forever::Context) { + loop { + let value = cx.local.my_channel.recv().await; + do_something_with_value(value); + } +} +``` + +## `spawn_after` and `spawn_at` have been removed. + +As discussed in the [Migrating to `rtic-monotonics`](./monotonics.md) chapter, `spawn_after` and `spawn_at` are no longer available. \ No newline at end of file -- cgit v1.2.3