actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.44k stars 1.66k forks source link

awc example does not run under tokio::main #3420

Closed piperck closed 3 months ago

piperck commented 3 months ago

Hi @robjtede, When I was trying to use awc to write a test client for myself, I encountered a small issue. Now, I want to try to fix it.🙋‍♀️

Expected Behavior

I hope to be able to directly use cargo run --example client to run awc.

Current Behavior

Currently, using the #[tokio::main] macro causes awc, which requires a single-threaded context, to fail to start and report an error.

thread 'main' panicked at awc/src/client/connection.rs:158:22:
`spawn_local` called from outside of a `task::LocalSet`

Possible Solution

Using #[actix_rt::main] instead of #[tokio::main] can solve this problem. Addtionally, I noticed that comments in other places have already been updated, but this one seems to have been overlooked. I've already raise a PR to fix this. https://github.com/actix/actix-web/pull/3421

Your Environment