I want to use it with #[tokio::main]
.
#300
-
I want to use is with Tokio main, how to do it?
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
you have to construct System and run it manually |
Beta Was this translation helpful? Give feedback.
-
example Line 50 in 68e158d |
Beta Was this translation helpful? Give feedback.
-
I tried many times and this works for me. #[tokio::main]
async fn main() -> io::Result<()> {
let ntex_handle = tokio::task::spawn_blocking(ntex_main);
_ = join!(ntex_handle);
Ok(())
}
#[ntex::main]
async fn ntex_main() -> io::Result<()> {
web::HttpServer::new(|| {
web::App::new().route(
"/",
web::get().to(|| async { web::HttpResponse::Ok().finish() }),
)
})
.bind("0.0.0.0:8000")?
.run()
.await?;
Ok(())
} I don't know why when I use this: fn ntex_main() -> io::Result<()> {
System::build().finish().block_on(
async move{
web::HttpServer::new(|| {
web::App::new().route(
"/",
web::get().to(|| async { web::HttpResponse::Ok().finish() }),
)
}).bind("0.0.0.0:8000")?.run().await?;
Ok(())
}
)
} I will get error
|
Beta Was this translation helpful? Give feedback.
-
by default tokio uses multi-threaded runtime, ntex requires single threaded |
Beta Was this translation helpful? Give feedback.
example
ntex/ntex/src/server/test.rs
Line 50 in 68e158d