Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions common/warp_utils/src/task.rs
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down Expand Up @@ -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
}
Loading
Loading