Struct Monitor

Source
pub struct Monitor { /* private fields */ }
Expand description

A monitor for coordinating and managing a collection of workers.

Implementations§

Source§

impl Monitor

Source

pub fn register<Req, S, P, Ctx>(self, worker: Worker<Ready<S, P>>) -> Self
where S: Service<Request<Req, Ctx>> + Send + 'static, S::Future: Send, S::Error: Send + Sync + 'static + Into<BoxDynError>, P: Backend<Request<Req, Ctx>> + Send + 'static, P::Stream: Unpin + Send + 'static, P::Layer: Layer<S> + Send, <P::Layer as Layer<S>>::Service: Service<Request<Req, Ctx>> + Send, <<P::Layer as Layer<S>>::Service as Service<Request<Req, Ctx>>>::Future: Send, <<P::Layer as Layer<S>>::Service as Service<Request<Req, Ctx>>>::Error: Send + Sync + Into<BoxDynError>, Req: Send + 'static, Ctx: Send + 'static,

Registers a single instance of a Worker

Source

pub fn register_with_count<Req, S, P, Ctx>( self, count: usize, worker: Worker<Ready<S, P>>, ) -> Self
where S: Service<Request<Req, Ctx>> + Send + 'static + Clone, S::Future: Send, S::Error: Send + Sync + 'static + Into<BoxDynError>, P: Backend<Request<Req, Ctx>> + Send + 'static + Clone, P::Stream: Unpin + Send + 'static, P::Layer: Layer<S> + Send, <P::Layer as Layer<S>>::Service: Service<Request<Req, Ctx>> + Send, <<P::Layer as Layer<S>>::Service as Service<Request<Req, Ctx>>>::Future: Send, <<P::Layer as Layer<S>>::Service as Service<Request<Req, Ctx>>>::Error: Send + Sync + Into<BoxDynError>, Req: Send + 'static, Ctx: Send + 'static,

👎Deprecated since 0.6.0: Consider using the .register as workers now offer concurrency by default

Registers multiple workers with the monitor.

§Arguments
  • count - The number of workers to register.
  • worker - A Worker that is ready for running.
§Returns

The monitor instance, with all workers added to the collection.

Source

pub async fn run_with_signal<S>(self, signal: S) -> Result<()>
where S: Send + Future<Output = Result<()>>,

Runs the monitor and all its registered workers until they have all completed or a shutdown signal is received.

§Arguments
  • signal - A Future that resolves when a shutdown signal is received.
§Errors

If the monitor fails to shutdown gracefully, an std::io::Error will be returned.

§Remarks

If a timeout has been set using the Monitor::shutdown_timeout method, the monitor will wait for all workers to complete up to the timeout duration before exiting. If the timeout is reached and workers have not completed, the monitor will exit forcefully.

Source

pub async fn run(self) -> Result<()>

Runs the monitor and all its registered workers until they have all completed.

§Errors

If the monitor fails to run gracefully, an std::io::Error will be returned.

§Remarks

If all workers have completed execution, then by default the monitor will start a shutdown

Source

pub fn on_event<F: Fn(Worker<Event>) + Send + Sync + 'static>( self, f: F, ) -> Self

Handles events emitted

Source§

impl Monitor

Source

pub fn new() -> Self

Creates a new monitor instance.

§Returns

A new monitor instance, with an empty collection of workers.

Source

pub fn shutdown_timeout(self, duration: Duration) -> Self

Sets a timeout duration for the monitor’s shutdown process.

§Arguments
  • duration - The timeout duration.
§Returns

The monitor instance, with the shutdown timeout duration set.

Source

pub fn with_terminator( self, fut: impl Future<Output = ()> + Send + 'static, ) -> Self

Sets a future that will start being polled when the monitor’s shutdown process starts.

After shutdown has been initiated, the terminator future will be run, and if it completes before all tasks are completed the shutdown process will complete, thus finishing the shutdown even if there are outstanding tasks. This can be useful for using a timeout or signal (or combination) to force a full shutdown even if one or more tasks are taking longer than expected to finish.

Trait Implementations§

Source§

impl Debug for Monitor

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Monitor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

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.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V