actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

`HttpServer::new` should support asynchronous application factories

Open vporton opened this issue 3 years ago • 1 comments

Expected Behavior

HttpServer::new should support asynchronous application factories as the argument.

Current Behavior

HttpServer::new(move || async move { ... });

fails.

Possible Solution

We either add new_async method or somehow make new work for both sync and async (if possible).

Context

I tried to allocate a thread object whose allocator uses an async method. It failed and now I don't know what to do.

Your Environment

  • Rust Version: 1.58.1
  • Actix Web Version: 4.0.0-rc.1

vporton avatar Feb 26 '22 11:02 vporton

There's been some work on this here #2413; it's something the team definitely wants to see.

For now, you can use the data_factory to initialize on workers' thread. Example.

robjtede avatar Mar 01 '22 05:03 robjtede