Attribute Macro embassy_macros::task

source ·
#[task]
Expand description

Declares an async task that can be run by embassy-executor. The optional pool_size parameter can be used to specify how many concurrent tasks can be spawned (default is 1) for the function.

The following restrictions apply:

  • The function must be declared async.
  • The function must not use generics.
  • The optional pool_size attribute must be 1 or greater.

Examples

Declaring a task taking no arguments:

#[embassy_executor::task]
async fn mytask() {
    // Function body
}

Declaring a task with a given pool size:

#[embassy_executor::task(pool_size = 4)]
async fn mytask() {
    // Function body
}