aboutsummaryrefslogtreecommitdiff
path: root/book/en/src/migration_v1_v2/async_tasks.md
diff options
context:
space:
mode:
authordatdenkikniet <jcdra1@gmail.com>2023-04-22 21:27:26 +0200
committerdatdenkikniet <jcdra1@gmail.com>2023-05-11 19:20:58 +0200
commit3d97c9e431d7fcb20b1b30bc15c34ccffee03c79 (patch)
tree6842b788361e247cc50423bee972cc7a3c6ba974 /book/en/src/migration_v1_v2/async_tasks.md
parented465b0c3b8b4c588f5cc7945af79a504f928cc8 (diff)
Move deprecated migration guides to deprecated folder
Diffstat (limited to 'book/en/src/migration_v1_v2/async_tasks.md')
-rw-r--r--book/en/src/migration_v1_v2/async_tasks.md55
1 files changed, 55 insertions, 0 deletions
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