Struct kvarn::shutdown::Manager

source ·
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§

Creates a new shutdown manager with the capacity of the list of wakers set to _capacity.

Adds a listener to this manager.

This is used so the accept future resolves immediately when the shutdown is triggered.

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.

Removes from the count of connections. If the count reaches 0 and the internal shutdown flag is enabled, it will initiate a graceful shutdown.

Retrieves the number of current connections. Returns 0 if the feature graceful-shutdown is disabled.

Available on crate feature graceful-shutdown only.

Gets the value of the internal shutdown flag. This signals a graceful shutdown is underway.

Wraps Self in a Arc to use across [tokio::task]s.

Available on crate feature 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.

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.

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.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more