This commit is contained in:
Michael Sproul
2025-05-08 20:52:50 +10:00
parent 2e50c2daea
commit 4d118a6ff2
18 changed files with 338 additions and 321 deletions

View File

@@ -1,5 +1,6 @@
use crate::reject::convert_rejection;
use serde::Serialize;
use std::future::Future;
use warp::reply::{Reply, Response};
/// A convenience wrapper around `blocking_task`.
@@ -38,3 +39,13 @@ where
convert_rejection(result).await
}
/// Async variant of `blocking_json_task`, which handles JSONification and error conversion.
pub async fn async_json_task<F, T>(fut: F) -> Response
where
F: Future<Output = Result<T, warp::Rejection>>,
T: Serialize + Send + 'static,
{
let result = fut.await.map(|response| warp::reply::json(&response));
convert_rejection(result).await
}