pub struct Manager { /* private fields */ }
Expand description
Shutdown manager. Contains a counter of connections and a shutdown flag to determine when to initiate a shutdown.
This will wait for all current connections to close, but immediately closes listeners.
Waiting on shutdown is handled using [tokio::sync::watch
].
Implementations§
source§impl Manager
impl Manager
sourcepub fn new(_capacity: usize) -> Self
pub fn new(_capacity: usize) -> Self
Creates a new shutdown manager with the capacity of the list of wakers set to _capacity
.
sourcepub fn get_initate_shutdown_watcher(&self) -> WatchReceiver<()>
Available on crate feature graceful-shutdown
only.
pub fn get_initate_shutdown_watcher(&self) -> WatchReceiver<()>
graceful-shutdown
only.Gets a watcher for when the shutdown is initiated
sourcepub fn add_connection(&self)
pub fn add_connection(&self)
Adds to the count of connections.
When this connection is closed, you must call Manager::remove_connection
or a logic error will occur and a shutdown will never happen.
sourcepub fn remove_connection(&self)
pub fn remove_connection(&self)
Removes from the count of connections. If the count reaches 0 and the internal shutdown flag is enabled, it will initiate a graceful shutdown.
sourcepub fn get_connecions(&self) -> isize
pub fn get_connecions(&self) -> isize
Retrieves the number of current connections.
Returns 0
if the feature graceful-shutdown is disabled
.
sourcepub fn get_shutdown(&self, order: Ordering) -> bool
Available on crate feature graceful-shutdown
only.
pub fn get_shutdown(&self, order: Ordering) -> bool
graceful-shutdown
only.Gets the value of the internal shutdown flag. This signals a graceful shutdown is underway.
sourcepub fn shutdown(&self)
Available on crate feature graceful-shutdown
only.
pub fn shutdown(&self)
graceful-shutdown
only.Makes Kvarn perform a graceful shutdown.
This requires you to be on a thread with a
Tokio runtime.
If you create new std
threads, you can use
Handle::current()
to get a movable handle of your runtime. Then call
Handle::enter
at the start of your thread’s execution and bind it to a shadow variable
(e.g. let _runtime = runtime_handle.enter()
). That keeps the reference alive during the
thread’s whole lifespan.
sourcepub async fn wait(&self)
pub async fn wait(&self)
Waits for Kvarn to enter the shutdown
state.
This is ran after the Self::wait_for_pre_shutdown
hook, which enables you to do work
before this is resolved.
If the feature graceful-shutdown
is disabled, this blocks forever.
sourcepub fn wait_for_pre_shutdown(
&self
) -> impl Future<Output = UnboundedSender<()>> + '_
pub fn wait_for_pre_shutdown( &self ) -> impl Future<Output = UnboundedSender<()>> + '_
Hooks into the stage before Kvarn signals it’s shutdown. Use with care. See comment below.
You MUST send ()
to the returned sender ONCE when you are done shutting down.
Abuse of this guarantee leads to unwanted timing of shutdown, or none.
You can call Self::shutdown
before awaiting the returned future.
If the feature graceful-shutdown
is disabled, this blocks forever.