pub struct CtrlC { /* private fields */ }Expand description
A handle to the process’s Ctrl+C signal, threaded explicitly through every function that
needs to react to it (execute, run_polling_loop, attempt_restore) rather than each
calling tokio::signal::ctrl_c() itself.
The CLI calls CtrlC::install exactly once, as early as possible in process startup;
runtime tests instead pass CtrlC::never and the server passes a manually-triggered
handle for each HTTP run. Tests never install a real process-wide signal handler. That
matters beyond this crate’s tests: once anything in a process calls
tokio::signal::ctrl_c(), the OS’s default “terminate on SIGINT” behavior is gone for the
rest of that process, so if any unit test installed a real handler, a developer’s own
Ctrl+C meant to abort a hung cargo test run could silently disappear into an idle
listener nothing is polling.
pub (rather than pub(crate)) so bhtune-server can name the type as it threads a
CtrlC::manual handle through crate::tune::drive_report for an HTTP-triggered run – see
that constructor’s doc comment. CtrlC::signalled itself deliberately stays
pub(crate): only code inside this crate (execute/run_polling_loop/attempt_restore)
ever needs to observe a cancellation, an external caller only ever needs to trigger
one, via a CtrlCHandle.
Implementations§
Source§impl CtrlC
impl CtrlC
Sourcepub fn install() -> CtrlC
pub fn install() -> CtrlC
Spawns the one long-lived task that listens for Ctrl+C for the rest of the process’s life, incrementing a counter on every delivery – see the struct doc comment for why this must be called exactly once, and only from real process startup.
Sourcepub fn manual() -> (CtrlC, CtrlCHandle)
pub fn manual() -> (CtrlC, CtrlCHandle)
Returns a fresh (CtrlC, CtrlCHandle) pair for a caller with no real OS Ctrl+C
keypress to listen for at all – bhtune-server’s background tune task, which needs
an HTTP request (POST /api/runs/{id}/cancel, or graceful shutdown) to be able to
trigger the exact same cancellation an interactive Ctrl+C would.
Deliberately not #[cfg(test)]-gated, unlike CtrlC::never/CtrlC::test_pair
above: those exist purely so this crate’s own unit tests can avoid installing a real
process-wide signal handler, but manual() never touches
tokio::signal/CtrlC::install at all, so calling it from production code any
number of times (once per in-flight run) carries none of that risk.
Auto Trait Implementations§
impl Freeze for CtrlC
impl RefUnwindSafe for CtrlC
impl Send for CtrlC
impl Sync for CtrlC
impl Unpin for CtrlC
impl UnsafeUnpin for CtrlC
impl UnwindSafe for CtrlC
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].