pub struct PerThreadShutdown { /* private fields */ }Expand description
Shutdown coordinator shared by every worker spawned via spawn_per_thread
(and friends). Workers select! against Self::notified in their accept
loop, so triggering PerThreadShutdown::trigger cleanly exits each
worker’s loop { accept } instead of leaking the OS thread on shutdown.
Backed by a tokio_util::sync::CancellationToken so the signal is
sticky: workers that register notified() after trigger() was called
still observe the request immediately, fixing the Notify::notify_waiters
race where late subscribers would miss the shutdown.
Also carries a private [BindStatus] that workers update with the result
of their SO_REUSEPORT bind so the parent (e.g. serve_per_thread) can
fail loudly on “every worker failed to bind” instead of returning Ok(()) —
previously the function would await Ctrl+C indefinitely and then claim
success even when no listener was up, a false health signal to supervisors.
Implementations§
Source§impl PerThreadShutdown
impl PerThreadShutdown
Sourcepub fn trigger(&self)
pub fn trigger(&self)
Notify every worker waiter that it should exit its accept loop. Idempotent — calling it more than once is a no-op.
Sourcepub async fn wait_for_bind_outcome(&self, total: usize) -> Result<()>
pub async fn wait_for_bind_outcome(&self, total: usize) -> Result<()>
Wait until either at least one worker bound successfully, or all
total workers reported a bind failure. Returns the first recorded
io::Error in the all-failure case so the caller can propagate a real
error instead of pretending the server started.
Trait Implementations§
Source§impl Clone for PerThreadShutdown
impl Clone for PerThreadShutdown
Source§fn clone(&self) -> PerThreadShutdown
fn clone(&self) -> PerThreadShutdown
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for PerThreadShutdown
impl Default for PerThreadShutdown
Source§fn default() -> PerThreadShutdown
fn default() -> PerThreadShutdown
Auto Trait Implementations§
impl Freeze for PerThreadShutdown
impl RefUnwindSafe for PerThreadShutdown
impl Send for PerThreadShutdown
impl Sync for PerThreadShutdown
impl Unpin for PerThreadShutdown
impl UnsafeUnpin for PerThreadShutdown
impl UnwindSafe for PerThreadShutdown
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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