#[task]Expand description
Background task handler — typed params, send_with enqueue, and link-time registration.
§Example
Assumes the worker (or enqueue host) is already booted and configured. For topology
choice see Mode 1 and
Mode 2.
use boson::{task, ExecutionContext};
#[task(name = "notify")]
async fn notify(
ctx: Box<dyn ExecutionContext>,
message: String,
) -> boson_core::Result<()> {
let _ = (ctx, message);
Ok(())
}
Notify::send_with(
serde_json::json!({"System": {"operation": "notify"}}),
NotifyParams { message: "hello".into() },
)
.await?;§Contract
- Function must be
async. - First parameter must be
Box<dyn ExecutionContext>. - Return type must be
Result<()>(typicallyboson_core::Result<()>). name = "..."is required and must be the first attribute.
§Policy attributes
Optional: priority, pool, max_attempts, base_delay_ms, backoff_multiplier,
max_delay_ms, max_in_flight, max_enqueue_per_second. Defaults and meanings are documented
on boson_macros.
Marks an async function as a Boson task.
Generates a params struct, a typed enqueue handle, and a registration entry for worker dispatch.
See the crate-level documentation for define/enqueue examples, policy attributes, and
worker boot (cross-link to the boson crate).
§Contract
- Function must be
async. - First parameter must be
Box<dyn ExecutionContext>. - Return type must be
Result<()>(typicallyboson_core::Result<()>). nameattribute is required (must be first).
§Policy attributes
Optional: priority, pool, idempotency_mode ("lwt" / "none"), max_attempts, base_delay_ms, backoff_multiplier,
max_delay_ms, max_in_flight, max_enqueue_per_second. See crate docs for defaults.