| Crates.io | asynq-macros |
| lib.rs | asynq-macros |
| version | 0.1.0 |
| created_at | 2025-10-12 13:44:54.749389+00 |
| updated_at | 2025-10-12 13:44:54.749389+00 |
| description | Procedural macros for asynq task handler registration |
| homepage | |
| repository | https://github.com/emo-crab/asynq |
| max_upload_size | |
| id | 1879301 |
| size | 10,882 |
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.
This crate provides the following macros:
#[task_handler("pattern")] - Define a synchronous task handler#[task_handler_async("pattern")] - Define an asynchronous task handlerAdd asynq with the macros feature to your Cargo.toml:
[dependencies]
asynq = { version = "0.1", features = ["macros"] }
Then use the macros to define your task handlers:
use asynq::{task::Task, error::Result, task_handler, task_handler_async};
// Define a synchronous task handler
#[task_handler("email:send")]
fn handle_email_send(task: Task) -> Result<()> {
println!("Sending email...");
Ok(())
}
// Define an asynchronous task handler
#[task_handler_async("image:resize")]
async fn handle_image_resize(task: Task) -> Result<()> {
println!("Resizing image...");
// Async operations here
Ok(())
}
Register the handlers with a ServeMux:
use asynq::{serve_mux::ServeMux, register_handlers, register_async_handlers};
let mut mux = ServeMux::new();
// Register sync handlers
register_handlers!(mux, handle_email_send);
// Register async handlers
register_async_handlers!(mux, handle_image_resize);