Skip to main content

Cancellation

Struct Cancellation 

Source
pub struct Cancellation { /* private fields */ }
Expand description

A shared handle that cancels a running request, or forwards signals to it.

Clones share the handle, so the engine keeps one clone and hands another to the tracer. When the flag is set, the tracer interrupts the request’s process tree, kills whatever remains of it after a grace period, and returns its result once the whole tree has exited. The result reports how the command ended: by a signal, or with an exit code that the command chose after it handled the interrupt.

The caller can also forward a Signal with Cancellation::forward, as kizz execute forwards the SIGTERM and SIGHUP that kizz receives. A tracer takes each forwarded signal with Cancellation::take_forwarded while the request runs, and delivers it once: to the command’s first process while that process lives, and afterwards to each live process of the tree. A signal that is forwarded again before the tracer takes it is delivered once, as a pending signal of the operating system is, and one forwarded while no request runs waits for the next request that holds a clone. Once the request is cancelled, the tracer forwards nothing more. Builds never forward a signal.

A signal sent to the whole process group of a command that keeps the terminal (RunRequest::terminal) reaches the command directly, and once more when the caller, which received it too, forwards it: neither the caller nor the tracer can tell such a signal from one sent to the caller alone.

The handle uses only atomic operations, so the caller can forward a signal from anywhere, a signal handler included.

Implementations§

Source§

impl Cancellation

Source

pub fn new() -> Self

A flag that is not set, with no signal forwarded.

Source

pub fn cancel(&self)

Request cancellation of every request that holds a clone of this flag.

Source

pub fn is_cancelled(&self) -> bool

Whether cancellation was requested.

Source

pub fn forward(&self, signal: Signal)

Forward signal to the request that holds a clone of this handle, for its tracer to deliver once, as the type’s documentation says.

Source

pub fn take_forwarded(&self) -> Vec<Signal>

Take every signal forwarded since the last call, in the order of Signal::ALL, so each one is delivered once.

Trait Implementations§

Source§

impl Clone for Cancellation

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cancellation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cancellation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.