pub struct Monitor<E> { /* private fields */ }
Expand description

A monitor for coordinating and managing a collection of workers.

Implementations§

source§

impl<E: Executor + Clone + Send + 'static + Sync> Monitor<E>

source

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

Registers a single instance of a Worker

source

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

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: Future<Output = Result<()>>>( self, signal: S ) -> Result<()>
where E: Executor + Clone + Send + 'static,

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.

source

pub async fn run(self) -> Result<()>
where E: Executor + Clone + Send + 'static,

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

§Errors

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

§Remarks

If a timeout has been set using the 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 log a warning message and exit forcefully.

source

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

Handles events emitted

source

pub fn executor(&self) -> &E

Get the current executor

source§

impl<E> Monitor<E>

source

pub fn new() -> Self
where E: Default,

Creates a new monitor instance.

§Returns

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

source

pub fn new_with_executor(executor: E) -> Self

Creates a new monitor instance with an executor

§Returns

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

source

pub fn set_executor<NE: Executor>(self, executor: NE) -> Monitor<NE>

Sets a custom executor for the monitor, allowing the usage of another runtime apart from Tokio. The executor must implement the Executor trait.

Trait Implementations§

source§

impl<E> Debug for Monitor<E>

source§

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

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

impl<E: Default> Default for Monitor<E>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<E> RefUnwindSafe for Monitor<E>
where E: RefUnwindSafe,

§

impl<E> Send for Monitor<E>
where E: Send,

§

impl<E> Sync for Monitor<E>
where E: Sync,

§

impl<E> Unpin for Monitor<E>
where E: Unpin,

§

impl<E> UnwindSafe for Monitor<E>
where E: UnwindSafe,

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>,

§

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>,

§

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.
§

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

§

fn vzip(self) -> V