Skip to content

How to trigger a shutdown from outside Rocket? #1880

Discussion options

You must be logged in to vote

It seems like the main barrier is going to be #[launch] - it's designed to replace Rust's (synchronous!) fn main() entry point, which you need for other things. You should take a look at the launch() function instead; for instance, you could do something like this:

// keeping this split out makes it easy to call 'rocket()' in tests
fn rocket() -> Rocket<Build> {
    rocket::build().attach(...).mount(...)
}

/// Spawns a Rocket server and returns its Shutdown handle
async fn spawn_rocket() -> Shutdown {
    let rocket = rocket().ignite().await;
    let shutdown_handle = rocket.shutdown();
    rocket::tokio::spawn(rocket.launch());
    shutdown_handle
}

The spawn_rocket() function can be ca…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
2 replies
@blackghost1987
Comment options

@jebrosen
Comment options

Answer selected by blackghost1987
Comment options

You must be logged in to vote
4 replies
@jebrosen
Comment options

@blackghost1987
Comment options

@blackghost1987
Comment options

@blackghost1987
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants