Skip to main content

CtrlC

Struct CtrlC 

Source
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.

CtrlC::install must be called exactly once, as early as possible, in the real binary’s startup (crate::run) – never from a function unit tests exercise. run_with_cli’s and commands::tune::run’s test-facing entry points instead default to [CtrlC::never] internally, so the many unit tests that exercise those functions never install a real process-wide signal handler. That matters beyond just those 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 commands::tune::drive 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

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more