Skip to main content

poll_task

Attribute Macro poll_task 

Source
#[poll_task]
Expand description

Apply to the PollTask trait definition, an impl PollTask<S [, K]> for T block, or — for less boilerplate — an inherent impl T { ... } block.

Use as #[cano::task::poll].

Two surface forms on impl blocks:

  1. Trait-impl form: #[task::poll] impl PollTask<S> for T { async fn poll(..) { ... } } — user writes the trait header. The macro async-rewrites the PollTask impl AND emits a companion impl Task<S> for T that delegates Task::run via the run_poll_loop helper.
  2. Inherent-impl form: #[task::poll(state = S [, key = K])] impl T { async fn poll(..) { ... } } — the macro builds the impl PollTask<S [, K]> for T header from the attribute args, enforces that poll is present (config / name may be overridden), and emits the same companion impl Task<S [, K]> for T.

On a trait definition (#[task::poll] pub trait PollTask ...) the macro just performs the async-fn-in-trait rewrite.

Because a blanket impl<P: PollTask<..>> Task<..> for P would conflict (E0119) with the analogous blanket impls for the other specialized task traits — a type can implement more than one — the companion Task impl is generated per-use-site rather than as a blanket.

The default config() injected by the inherent form is [TaskConfig::minimal()] (no retries) — the poll loop itself is the resilience mechanism.