pub struct GracefulTimeouts {
pub interrupt_timeout: Duration,
pub terminate_timeout: Duration,
}Expand description
Per-platform graceful-shutdown timeout budget passed to ProcessHandle::terminate and
related APIs.
The shape mirrors the platform’s actual graceful-shutdown model. On Unix the type carries
two separate timeout, one per graceful phase (SIGINT then SIGTERM). On Windows it carries
a single timeout for the single graceful phase (CTRL_BREAK_EVENT) on that platform.
§Cross-platform construction
Use GracefulTimeouts::builder to write a single cross-platform construction expression.
The setter for the platform that does not match the current target accepts its arguments
without using them, so no cfg gates are needed at the call site:
use std::time::Duration;
use tokio_process_tools::{GracefulTimeouts, both};
let timeouts = GracefulTimeouts::builder()
.unix((Duration::from_secs(3), Duration::from_secs(5)))
.windows(Duration::from_secs(8))
.build();
// For the common case where both Unix phases share a value:
let timeouts = GracefulTimeouts::builder()
.unix(both(Duration::from_secs(3)))
.windows(Duration::from_secs(8))
.build();§Platform-specific construction
Code that intentionally tunes Unix and Windows independently can also construct the value directly with cfg gates:
use std::time::Duration;
use tokio_process_tools::GracefulTimeouts;
#[cfg(unix)]
let timeouts = GracefulTimeouts {
interrupt_timeout: Duration::from_secs(3),
terminate_timeout: Duration::from_secs(5),
};
#[cfg(windows)]
let timeouts = GracefulTimeouts {
graceful_timeout: Duration::from_secs(8),
};§Platform availability
This type is only available on Unix and Windows because the underlying graceful-shutdown
signals only exist there. On other Tokio-supported targets the spawn, wait,
output-collection, and ProcessHandle::kill APIs remain available; only the
graceful-termination surface (terminate(...), terminate_on_drop(...),
wait_for_completion_or_terminate(...), the send_*_signal(...) methods, and this type) is
gated out.
Fields§
§interrupt_timeout: DurationMaximum time to wait after sending SIGINT before escalating to SIGTERM.
terminate_timeout: DurationMaximum time to wait after sending SIGTERM before escalating to SIGKILL.
Implementations§
Source§impl GracefulTimeouts
impl GracefulTimeouts
Sourcepub fn builder() -> GracefulTimeoutsBuilder<UnixUnset>
pub fn builder() -> GracefulTimeoutsBuilder<UnixUnset>
Start a fluent specification of a GracefulTimeouts value.
Call unix, then
windows, then
build. The setter for the platform that does not
match the current target accepts its arguments without using them, which lets
cross-platform code construct the value without cfg gates.
See the type-level documentation for an example.
Trait Implementations§
Source§impl Clone for GracefulTimeouts
impl Clone for GracefulTimeouts
Source§fn clone(&self) -> GracefulTimeouts
fn clone(&self) -> GracefulTimeouts
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more