diff options
| author | datdenkikniet <jcdra1@gmail.com> | 2023-04-22 17:37:15 +0200 |
|---|---|---|
| committer | datdenkikniet <jcdra1@gmail.com> | 2023-05-11 19:20:58 +0200 |
| commit | 1dc2f80eb6cb6ac6d1eaede4169d8cabc51c5e7c (patch) | |
| tree | 0c86b2a70ec77e9e12b3bf0d764110f235efc804 /book/en/src/migration/migration_v2/async_tasks.md | |
| parent | 16f8ea9ba7d0fed1c9f1622b2e9cbcdbbdd807f5 (diff) | |
Begin migration guide
Diffstat (limited to 'book/en/src/migration/migration_v2/async_tasks.md')
| -rw-r--r-- | book/en/src/migration/migration_v2/async_tasks.md | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/book/en/src/migration/migration_v2/async_tasks.md b/book/en/src/migration/migration_v2/async_tasks.md new file mode 100644 index 0000000..54e0893 --- /dev/null +++ b/book/en/src/migration/migration_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 |
