'call an async function in actix-web middleware

I implemented a actix-web middleware but i'm having issues trying to retrieve a client object from a database pool because that call is an async function:

impl <S, B> Service<ServiceRequest> for SomeMiddleware<S>
...
fn call(&self, request: ServiceRequest) -> Self::Future {
  if let Some(pool) = request.app_data::web::Data<Pool>>() {
     // this call will not work
     let client = pool.get().await.unwrap();
  }
}

How do I get a client object from the pool?

I am using actix-web 4.x and deadpool-postgres.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source