actix-web-async-await
                                
                                
                                
                                    actix-web-async-await copied to clipboard
                            
                            
                            
                        App.resource example please
Hi, could you give example how to use async fn with App.resource?
Is it possible?
Any news on this?
I don't personally use .resource in my stuff. Sorry if it doesn't work in that case. Good news is Actix 1.0 natively supports async fn and you can toss this crate when that's out (soon as far as I can tell).
Good news is Actix 1.0 natively supports async fn
Not sure this is correct, no mention of it anywhere in the repo. Struggling to port my async code to actix 1.0 at moment.
As far as I can see actix 1.0 does not support async/await out of the box. I am not very well versed with Futures and I am struggling too: if this repo could get updated to the new actix version it would greatly simplify the story for async actix experiments.
As far as I can see actix 1.0 does not support async/await out of the box.
I think the best we can do right now is to wrap the futures like this:
[dependencies]
futures-preview = { version = "0.3.0-alpha.16", features = ["compat"] }
futures01 = { package = "futures", version = "0.1" }
#![feature(async_await, await_macro)]
use futures::compat::{Compat, Compat01As03};
// I want to run this future    
async fn my_fn_async(_req: HttpRequest) -> Result<HttpResponse, actix_web::Error> {
    Ok(HttpResponse::Ok().finish())
}
// I need to wrap it
fn test(
    req: HttpRequest,
) -> impl futures01::future::Future<Item = HttpResponse, Error = actix_web::Error> {
    Compat::new(Box::pin(my_fn_async(req)))
}
fn main() {
    HttpServer::new(|| {
        App::new()
            .service(web::resource("/test").to_async(test))
    })
    .bind("127.0.0.1:8080").unwrap()
    .run()
}
                                    
                                    
                                    
                                
You might be interested in this example: https://github.com/actix/examples/pull/132