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§

source§

impl Manager

source

pub fn new(_capacity: usize) -> Self

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

source

pub fn get_initate_shutdown_watcher(&self) -> WatchReceiver<()>

Available on crate feature graceful-shutdown only.

Gets a watcher for when the shutdown is initiated

source

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.

source

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.

source

pub fn get_connecions(&self) -> isize

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

source

pub fn get_shutdown(&self, order: Ordering) -> bool

Available on crate feature graceful-shutdown only.

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

source

pub fn build(self) -> Arc<Self>

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

source

pub fn shutdown(&self)

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.

source

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.

source

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.

Trait Implementations§

source§

impl Debug for Manager

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 Twhere U: From<T>,

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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