-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
!Send handlers #362
Comments
One cannot use let svc = tower::service_fn(|_: Request<Body>| async {
let rc = std::rc::Rc::new(());
std::future::ready(()).await;
rc.clone();
Ok::<_, hyper::Error>(http::Response::new(Body::empty()))
});
hyper::Server::bind(&"".parse().unwrap())
.serve(tower::make::Shared::new(svc))
.await
.unwrap(); This doesn't compile
So not sure there is much we can do in axum. Personally I think spawning a task and communicating via channels to be fine for working with Creating a runtime for each thread doesn't seem like its worth it. I don't know what the memory and performance implications are but to me it feels like the right approach to stick with tokio's multithreaded runtime. |
Think I'll close this for now as this isn't something we plan on adding support for. I think it would require changes that would hurt users who don't need |
Some datastructures are inherently non Send. It would be great if Axum could take advantage of Tokio's ability to run only thread-local tasks and only have Thread-local handlers.
Right now, handlers may be !Sync, but they must be Send. It would be great if handlers could be !Send and !Sync within their handling code - the creation of the task could be Send.
For reference, actix manually spins up an executor for each thread in a thread pool, then runs server futures on a LocalSet.
rust-lang/wg-async#87 (comment)
This means it's possible to support !Send handlers while also using the native runtime.
The text was updated successfully, but these errors were encountered: