mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
docs: improve docs about tokio::main
This commit is contained in:
parent
bf22fecbcd
commit
0950e1624d
@ -1,10 +1,10 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use actix_web::HttpMessage as _;
|
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
body::MessageBody,
|
body::MessageBody,
|
||||||
dev::{ServiceRequest, ServiceResponse},
|
dev::{ServiceRequest, ServiceResponse},
|
||||||
http::header::{HeaderName, HeaderValue},
|
http::header::{HeaderName, HeaderValue},
|
||||||
|
HttpMessage as _,
|
||||||
};
|
};
|
||||||
use actix_web_lab::middleware::Next;
|
use actix_web_lab::middleware::Next;
|
||||||
use tracing_actix_web::RequestId;
|
use tracing_actix_web::RequestId;
|
||||||
|
@ -32,6 +32,7 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for AutobahnWebSocket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the actor-based WebSocket examples REQUIRE `actix_web::main` for actor support
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
@ -47,7 +47,6 @@ async fn chat_ws(
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
// note that the actor-based WebSocket examples would NOT work under `tokio::main`
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
@ -16,6 +16,7 @@ async fn chat_ws(req: HttpRequest, stream: web::Payload) -> Result<impl Responde
|
|||||||
ws::start(WsChatSession::default(), &req, stream)
|
ws::start(WsChatSession::default(), &req, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the actor-based WebSocket examples REQUIRE `actix_web::main` for actor support
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
@ -220,6 +220,7 @@ impl WsChatSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the actor-based WebSocket examples REQUIRE `actix_web::main` for actor support
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
@ -45,6 +45,7 @@ async fn get_count(count: web::Data<AtomicUsize>) -> impl Responder {
|
|||||||
format!("Visitors: {current_count}")
|
format!("Visitors: {current_count}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the actor-based WebSocket examples REQUIRE `actix_web::main` for actor support
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
@ -65,7 +65,6 @@ async fn broadcast_ws(
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
// note that the actor-based WebSocket examples would NOT work under `tokio::main`
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
@ -18,6 +18,7 @@ async fn echo_ws(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse,
|
|||||||
ws::start(MyWebSocket::new(), &req, stream)
|
ws::start(MyWebSocket::new(), &req, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the actor-based WebSocket examples REQUIRE `actix_web::main` for actor support
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
Loading…
Reference in New Issue
Block a user