Skip to main content

CloseBudget

Struct CloseBudget 

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

A finite budget for a shutdown, started once and spent by every phase of it.

Why the type exists. A close has phases — stop admitting work, let what is already finished reach the peer, then close the sockets and wait for them to go idle — and each phase’s wait is decided by somebody else’s network. Without one budget spanning all of them, the length of a close is whatever the slowest peer makes it: QUIC’s closing and draining periods last about three times the path’s probe timeout, and ZeroMQ’s ZMQ_LINGER defaults to infinite, which is why zmq_ctx_term() is known as a place processes hang (docs/research/zeromq.md §12/P17). A process that must exit within a budget of its own cannot use an API like that (decisions/0009 §4.3, §4.4).

So: one budget, taken at the start, and each phase asks how much is left. A phase that overruns leaves the next one Duration::ZERO rather than a negative number, which is a bound that still holds rather than a wait that starts over.

let budget = CloseBudget::start(Duration::from_secs(1));
// First phase waits on `budget.remaining()`, and so does the next.
assert!(budget.remaining() <= Duration::from_secs(1));
assert_eq!(budget.limit(), Duration::from_secs(1));

Implementations§

Source§

impl CloseBudget

Source

pub fn start(limit: Duration) -> CloseBudget

Starts a budget of limit, from now.

Source

pub const fn limit(&self) -> Duration

What the whole budget was, regardless of what is left of it.

Source

pub fn remaining(&self) -> Duration

What is left, saturating at Duration::ZERO: the bound the next phase of the close gets.

Source

pub fn is_spent(&self) -> bool

Whether the budget is used up. A spent budget still bounds: the next phase gets zero and does not wait.

Trait Implementations§

Source§

impl Clone for CloseBudget

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 Copy for CloseBudget

Source§

impl Debug for CloseBudget

Source§

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

Formats the value using the given formatter. 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.