Skip to main content

main

Attribute Macro main 

Source
#[main]
Expand description

Runs an async function on the ntex runtime.

Re-exported as ntex::main.

The function becomes a normal blocking function. When called, it builds a System, runs the body to completion and returns its result, so the function can return a value, for example std::io::Result<()>. It does not have to be main.

#[ntex::main]
async fn main() -> std::io::Result<()> {
    println!("Hello world");
    Ok(())
}

ยงArguments

  • name = "..." - name of the system. Defaults to the function name.
  • signals = true/false - handle process signals. Off by default.
  • panic_handling = true/false - report application panics as Signal::Panic. Only useful together with signals = true. Off by default.
  • ping_interval = N - how often, in milliseconds, the system pings its arbiters to spot busy ones. Defaults to 2000, zero turns pings off.
  • rt = path - the runtime to run on, a value that implements ntex::rt::Runner. Defaults to ntex::rt::DefaultRuntime, the runtime picked by ntex features.
#[ntex::main(name = "server", signals = true, ping_interval = 250)]
async fn main() {
    println!("Hello world");
}