Skip to main content

sync_task

Attribute Macro sync_task 

Source
#[sync_task]
Expand description

Turn an inherent impl Block { fn run(...) -> ... } into a SyncTask/AsyncTask trait implementation for the taskflow scheduler.

§Accepted run signatures

// 1. No inputs, no context (source task).
fn run(self) -> Out;

// 2. Only DAG inputs.
fn run(self, a: &A, b: &B) -> Out;

// 3. With the runtime FlowContext. MUST be the first non-self parameter,
//    typed as `&FlowContext` (match by trailing path segment, so any
//    import alias that still names the type `FlowContext` works).
fn run(self, ctx: &FlowContext, a: &A) -> Out;

DAG inputs must be shared references &T (the scheduler stores outputs as Arc<T> and hands out a borrow). Owned and &mut parameters are rejected.

§Context injection details

The generated trait impl always takes ctx: &FlowContext. If the user did not declare one, the generated body discards it with let _ = ctx;. If the user did declare one, it is forwarded as the first argument to the inherent run call. Nothing else in the user’s signature changes.

§The path = "..." attribute

When the macro is used outside the taskflow crate itself, pass path = "::taskflow" (or the relevant re-export root) so the generated code can refer to the runtime traits. Inside the taskflow crate the default crate path is used.