actix-web
actix-web copied to clipboard
async `HttpServer::new` as alternative to `data_factory`
Part of the apeal of App::data_factory is that it uses the local reactor when instantiating app data. It's equivalent and more natural to make HttpServer::new async.
Regarding this, I have a data preparation function that needs to be async, and needs to be called for each thread, giving slightly different things to each one (for example, distinct tokio-postgres clients, that are not Clone). So I can't just prepare the data before configuring the server and call data.clone(). We can argue that pooling the postgres connection might be a good idea, but I'm really wondering how I can deal with this case right now without using the deprecated data_factory...
I tried a few things but it seems hard, or super hacky. Or maybe I just missed something? But if not, I think it would be nice to have a good alternative to data_factory before deprecating it.