1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-02-20 09:40:34 +01:00

turned inner methods into async ones

This commit is contained in:
dowwie 2019-12-16 11:43:35 -05:00
parent d3819b7588
commit 2c5679f498

View File

@ -207,10 +207,10 @@ struct Inner {
} }
impl Inner { impl Inner {
fn load( async fn load(
&self, &self,
req: &ServiceRequest, req: &ServiceRequest,
) -> impl Future<Output = Result<Option<(HashMap<String, String>, String)>, Error>> ) -> Result<Option<(HashMap<String, String>, String)>, Error>
{ {
if let Ok(cookies) = req.cookies() { if let Ok(cookies) = req.cookies() {
for cookie in cookies.iter() { for cookie in cookies.iter() {
@ -220,7 +220,7 @@ impl Inner {
if let Some(cookie) = jar.signed(&self.key).get(&self.name) { if let Some(cookie) = jar.signed(&self.key).get(&self.name) {
let value = cookie.value().to_owned(); let value = cookie.value().to_owned();
let cachekey = (self.cache_keygen)(&cookie.value()); let cachekey = (self.cache_keygen)(&cookie.value());
return Either::Left( return
self.addr.send(Command(resp_array!["GET", cachekey])).map( self.addr.send(Command(resp_array!["GET", cachekey])).map(
|result| match result { |result| match result {
Err(e) => Err(Error::from(e)), Err(e) => Err(Error::from(e)),
@ -257,23 +257,23 @@ impl Inner {
} }
}, },
}, },
), )
); .await;
} else { } else {
return Either::Right(ok(None)); return ok(None).await
} }
} }
} }
} }
Either::Right(ok(None)) ok(None).await
} }
fn update<B>( async fn update<B>(
&self, &self,
mut res: ServiceResponse<B>, mut res: ServiceResponse<B>,
state: impl Iterator<Item = (String, String)>, state: impl Iterator<Item = (String, String)>,
value: Option<String>, value: Option<String>,
) -> impl Future<Output = Result<ServiceResponse<B>, Error>> { ) -> Result<ServiceResponse<B>, Error> {
let (value, jar) = if let Some(value) = value { let (value, jar) = if let Some(value) = value {
(value.clone(), None) (value.clone(), None)
} else { } else {
@ -311,8 +311,8 @@ impl Inner {
let state: HashMap<_, _> = state.collect(); let state: HashMap<_, _> = state.collect();
match serde_json::to_string(&state) { match serde_json::to_string(&state) {
Err(e) => Either::Left(err(e.into())), Err(e) => err(e.into()).await,
Ok(body) => Either::Right( Ok(body) =>
self.addr self.addr
.send(Command(resp_array!["SET", cachekey, body, "EX", &self.ttl])) .send(Command(resp_array!["SET", cachekey, body, "EX", &self.ttl]))
.map(|result| match result { .map(|result| match result {
@ -331,13 +331,13 @@ impl Inner {
} }
Err(err) => Err(error::ErrorInternalServerError(err)), Err(err) => Err(error::ErrorInternalServerError(err)),
}, },
}), })
), .await,
} }
} }
/// removes cache entry /// removes cache entry
fn clear_cache(&self, key: String) -> impl Future<Output = Result<(), Error>> { async fn clear_cache(&self, key: String) -> Result<(), Error> {
let cachekey = (self.cache_keygen)(&key); let cachekey = (self.cache_keygen)(&key);
self.addr self.addr
@ -354,6 +354,7 @@ impl Inner {
} }
} }
}) })
.await
} }
/// invalidates session cookie /// invalidates session cookie