How can I call an async function in actix-web middleware?
01:49 15 Apr 2022

I implemented an 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  Service for SomeMiddleware
...
fn call(&self, request: ServiceRequest) -> Self::Future {
  if let Some(pool) = request.app_data::web::Data>() {
     // 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.

rust actix-web