Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider allowing a SystemRunner::block_on() future to listen for System::stop() #588

Open
finnbear opened this issue Aug 4, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@finnbear
Copy link

finnbear commented Aug 4, 2024

I use SystemRunner::block_on() in my main function to run my http server. It is ergonomic since it passes through my std::process::ExitCode return value from my future. Now I would like to use System::current().stop() to shutdown my server. Unfortunately, I don't see a way to await the stop event within my block_on future.

One possible design:

fn main() -> ExitCode {
    let (runtime, stop) = System::new().into_parts(); // or `into_runtime_and_stop()`
    runtime.block_on(async move {
        let http_server = axum::serve(...System::current().stop()...);
        tokio::select {
            _ = stop => {
                return ExitCode::SUCCESS;
            }
            _ = http_server => {
                 return ExitCode::FAILURE;
            }
        }
    })
}

I considered multiple workarounds, and am currently constructing an extra Oneshot channel and passing it around my application (losing the benefit of System::current().stop() working anywhere).

@robjtede robjtede added enhancement New feature or request help wanted Extra attention is needed labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants