Skip to main content

Gate

Struct Gate 

Source
pub struct Gate { /* private fields */ }

Implementations§

Source§

impl Gate

Source

pub fn new(max_count: Option<usize>, acquire_timeout: Duration) -> Self

Create a new gate with optional max connections and acquire timeout.

  • max_count: Maximum concurrent connections (None = no configured limit). The counter supports up to isize::MAX concurrent permits.
  • acquire_timeout: How long to wait for a slot when at capacity
Source

pub fn grace_period(&self) -> Option<Duration>

Returns the complete caller-declared grace period (None is indefinite).

Source

pub fn count(&self) -> usize

Get the number of connections.

Source

pub fn max_count(&self) -> Option<usize>

Admission capacity; None means unlimited.

Source

pub fn force_shutdown(&self)

Trigger a forced (hard) shutdown. Wakes all waiters of wait_shutdown(). This is only called by wait_all_done() when the grace period elapses. External code should not call this directly.

Source

pub fn graceful_shutdown(&self, duration: Option<Duration>)

Begin a graceful shutdown phase. Notifies graceful and records the optional grace period. This does not imply a forced/Hard shutdown signal.

None means indefinite grace period (critical tasks mode).

Source

pub fn is_shutting_down(&self) -> bool

Source

pub async fn wait_forced_shutdown(&self)

Wait for the forced (hard) shutdown signal. This does not fire for a clean drain. Private to this module; external code should use Permit::wait_forced_shutdown.

Source

pub async fn wait_graceful_shutdown(&self)

Source

pub async fn enter(&self) -> Result<Permit, Error>

Enter the gate, waiting up to the configured acquire timeout if the gate is currently at capacity.

Returns a Permit token. Dropping the permit leaves the gate.

Source

pub fn try_enter(&self) -> Result<Permit, Error>

Try to enter the gate immediately without waiting for capacity.

This is where the limit is enforced, for both doors: enter waits and retries around this rather than testing the count itself.

Source

pub async fn wait_all_done(&self) -> GateDrainOutcome

Wait until all permits are dropped, respecting the configured grace period. If the grace period elapses, this triggers force_shutdown() and reports the number of permits that remained when the hard signal was sent. Note: when returning via the forced path, count() may still be > 0 for a short time until connection tasks observe the hard signal and drop.

§Call graceful_shutdown first

Before that signal this call does not return, even once the last permit is gone: all_done is a one-shot, and a permit released during ordinary operation would latch it permanently, so Permit::drop only fires it when graceful shutdown has already been asked for. Waiting without asking is therefore waiting for a signal nobody will send — which is also the right behaviour, since the grace-then-force path is only meaningful once the work has been told to wind down.

Trait Implementations§

Source§

impl Clone for Gate

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 Gate

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Gate

§

impl Freeze for Gate

§

impl RefUnwindSafe for Gate

§

impl Send for Gate

§

impl Sync for Gate

§

impl Unpin for Gate

§

impl UnsafeUnpin for Gate

§

impl UnwindSafe for Gate

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> Instrument for T

Source§

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

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

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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