Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Support for a shutdown signal #319

Open
zeenix opened this issue Jan 31, 2023 · 0 comments
Open

Support for a shutdown signal #319

zeenix opened this issue Jan 31, 2023 · 0 comments
Labels
enhancement New feature or request zbus Issues/PRs related to zbus crate

Comments

@zeenix
Copy link
Collaborator

zeenix commented Jan 31, 2023

In GitLab by @Peelz on Jan 31, 2023, 02:08

zbus could have an API for requesting the connection to be closed.

This ties in #307

As an example, here's how hyper handles this:

let server = Server::bind(&addr)
    .serve(make_service);

// Prepare some signal for when the server should start shutting down...
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
let graceful = server
    .with_graceful_shutdown(async {
        rx.await.ok();
    });

// Await the `server` receiving the signal...
if let Err(e) = graceful.await {
    eprintln!("server error: {}", e);
}

// And later, trigger the signal by calling `tx.send(())`.
let _ = tx.send(());

For comparison, the simple "wait forever" implementation with no shutdown signal:

let server = Server::bind(&addr)
    .serve(make_service);

// Run forever-ish...
if let Err(err) = server.await {
    eprintln!("server error: {}", err);
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request zbus Issues/PRs related to zbus crate
Projects
None yet
Development

No branches or pull requests

1 participant