pub struct Gate { /* private fields */ }Implementations§
Source§impl Gate
impl Gate
Sourcepub fn new(max_count: Option<usize>, acquire_timeout: Duration) -> Self
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 toisize::MAXconcurrent permits.acquire_timeout: How long to wait for a slot when at capacity
Sourcepub fn grace_period(&self) -> Option<Duration>
pub fn grace_period(&self) -> Option<Duration>
Returns the complete caller-declared grace period (None is indefinite).
Sourcepub fn force_shutdown(&self)
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.
Sourcepub fn graceful_shutdown(&self, duration: Option<Duration>)
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).
pub fn is_shutting_down(&self) -> bool
Sourcepub async fn wait_forced_shutdown(&self)
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.
pub async fn wait_graceful_shutdown(&self)
Sourcepub async fn enter(&self) -> Result<Permit, Error>
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.
Sourcepub fn try_enter(&self) -> Result<Permit, Error>
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.
Sourcepub async fn wait_all_done(&self) -> GateDrainOutcome
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.