actix-web 2.0 does run start an actix system?

Created on 11 Jan 2020  路  2Comments  路  Source: actix/actix-web

In actix-web 1.0, start() only started the HttpServer, and run also started an actix System.
According to the change list, in 2.0 start() was renamed to run().
Does it mean actix-web 2.0 doesn't actually need a running System any more?

What if we start a System for when we use our actix actors as well, and want to run actix-web in it too, just like this example for 1.0?
https://github.com/actix/examples/blob/49308b70e50af31ebece1209185c9a17e30b6ac0/websocket-chat-broker/src/main.rs#L155

v2.x

Most helpful comment

AFAICT, actix-web still needs a running System and that's why the new examples all use

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    // ...
}

You can do the same thing manually like this (that's what actix_rt::main generates):

fn main() -> std::io::Result<()> {
    actix_rt::System::new("<name>")
        .block_on(async move {
            // ...
        })
}

All 2 comments

AFAICT, actix-web still needs a running System and that's why the new examples all use

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    // ...
}

You can do the same thing manually like this (that's what actix_rt::main generates):

fn main() -> std::io::Result<()> {
    actix_rt::System::new("<name>")
        .block_on(async move {
            // ...
        })
}

I can recommend using cargo-expand on a simple example to see the generated code after the actix_rt macro is expanded out. Short story, yes a System is still required in v2.x

Was this page helpful?
0 / 5 - 0 ratings