pub fn blocking<F, R>(
f: F,
) -> impl Fn() -> Pin<Box<dyn Future<Output = Response> + Send>> + CloneExpand description
Wrap a synchronous (blocking) function as an Axum handler.
The function will be dispatched to Tokio’s blocking thread pool via
tokio::task::spawn_blocking. This prevents CPU-bound work from
starving the async executor.
§Example
use vil_server_core::sync_handler::blocking;
// CPU-bound handler — runs on blocking thread pool
fn predict(body: Vec<u8>) -> String {
// Heavy computation...
format!("Processed {} bytes", body.len())
}
// Use in route:
// .route("/predict", post(blocking(predict)))