Asynq Macros
Procedural macros for the asynq task queue library, providing a convenient way to define and register task handlers using attribute macros similar to actix-web's routing macros.
Features
This crate provides the following macros:
#[task_handler("pattern")]- Define a synchronous task handler#[task_handler_async("pattern")]- Define an asynchronous task handler
Usage
Add asynq with the macros feature to your Cargo.toml:
[]
= { = "0.1", = ["macros"] }
Then use the macros to define your task handlers:
use ;
// Define a synchronous task handler
// Define an asynchronous task handler
async
Register the handlers with a ServeMux:
use ;
let mut mux = new;
// Register sync handlers
register_handlers!;
// Register async handlers
register_async_handlers!;
Benefits
- Declarative syntax: Define handlers with a clean attribute syntax
- Type safety: Pattern strings are validated at compile time
- Reduced boilerplate: Automatic pattern association with handlers
- Similar to web frameworks: Familiar pattern for developers coming from actix-web or similar frameworks