convert plume-models to all async

where sensible! note that State has no asynchronous work to do, so
wrapping it up in async makes no sense.
This commit is contained in:
Igor Galić 2020-01-26 20:59:48 +01:00
parent ce119ffe50
commit 59e5c49aa8
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
2 changed files with 5 additions and 5 deletions

View File

@ -28,7 +28,7 @@ impl<'a, 'r> FromRequestAsync<'a, 'r> for DbConn {
Box::pin(async move { Box::pin(async move {
match DbConn::from_request(request).await { match DbConn::from_request(request).await {
Outcome::Success(a) => return Outcome::Success(a), Outcome::Success(a) => return Outcome::Success(a),
Outcome::Failure(_) => return Outcome::Failure((Status::ServiceUnavailable, ())), _ => return Outcome::Failure((Status::ServiceUnavailable, ())),
}; };
}) })
} }

View File

@ -4,7 +4,7 @@ pub use self::module::PlumeRocket;
mod module { mod module {
use crate::{db_conn::DbConn, search, users}; use crate::{db_conn::DbConn, search, users};
use rocket::{ use rocket::{
request::{self, FlashMessage, FromRequest, FromRequestAsync, Request}, request::{self, FlashMessage, FromRequestAsync, Request},
Outcome, State, Outcome, State,
}; };
use scheduled_thread_pool::ScheduledThreadPool; use scheduled_thread_pool::ScheduledThreadPool;
@ -28,13 +28,13 @@ mod module {
let conn = try_outcome!(DbConn::from_request(request).await); let conn = try_outcome!(DbConn::from_request(request).await);
let intl = try_outcome!(rocket_i18n::I18n::from_request(request).await); let intl = try_outcome!(rocket_i18n::I18n::from_request(request).await);
let user = try_outcome!(users::User::from_request(request).await); let user = try_outcome!(users::User::from_request(request).await);
let worker = request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>()?; let worker = try_outcome!(request.guard::<'_, State<'_, Arc<ScheduledThreadPool>>>());
let searcher = request.guard::<'_, State<'_, Arc<search::Searcher>>>()?; let searcher = try_outcome!(request.guard::<'_, State<'_, Arc<search::Searcher>>>());
let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded(); let flash_msg = request.guard::<FlashMessage<'_, '_>>().succeeded();
Outcome::Success(PlumeRocket { Outcome::Success(PlumeRocket {
conn, conn,
intl, intl,
user, user: Some(user),
flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())), flash_msg: flash_msg.map(|f| (f.name().into(), f.msg().into())),
worker: worker.clone(), worker: worker.clone(),
searcher: searcher.clone(), searcher: searcher.clone(),