pub struct Monitor<E> { /* private fields */ }
Expand description
A monitor for coordinating and managing a collection of workers.
Implementations§
source§impl<E> Monitor<E>
impl<E> Monitor<E>
sourcepub fn register<J, S, P>(self, worker: Worker<Ready<S, P>>) -> Monitor<E>where
J: Send + Sync + 'static,
S: Service<Request<J>> + Send + 'static + Clone,
P: Backend<Request<J>> + 'static,
<S as Service<Request<J>>>::Future: Send,
<S as Service<Request<J>>>::Response: 'static,
<S as Service<Request<J>>>::Error: Send + Sync + 'static + Into<Box<dyn Error + Sync + Send>>,
<P as Backend<Request<J>>>::Stream: Unpin + Send + 'static,
pub fn register<J, S, P>(self, worker: Worker<Ready<S, P>>) -> Monitor<E>where
J: Send + Sync + 'static,
S: Service<Request<J>> + Send + 'static + Clone,
P: Backend<Request<J>> + 'static,
<S as Service<Request<J>>>::Future: Send,
<S as Service<Request<J>>>::Response: 'static,
<S as Service<Request<J>>>::Error: Send + Sync + 'static + Into<Box<dyn Error + Sync + Send>>,
<P as Backend<Request<J>>>::Stream: Unpin + Send + 'static,
Registers a single instance of a Worker
sourcepub fn register_with_count<J, S, P>(
self,
count: usize,
worker: Worker<Ready<S, P>>
) -> Monitor<E>where
J: Send + Sync + 'static,
S: Service<Request<J>> + Send + 'static + Clone,
P: Backend<Request<J>> + 'static,
<S as Service<Request<J>>>::Future: Send,
<S as Service<Request<J>>>::Response: 'static,
<S as Service<Request<J>>>::Error: Send + Sync + 'static + Into<Box<dyn Error + Sync + Send>>,
<P as Backend<Request<J>>>::Stream: Unpin + Send + 'static,
pub fn register_with_count<J, S, P>(
self,
count: usize,
worker: Worker<Ready<S, P>>
) -> Monitor<E>where
J: Send + Sync + 'static,
S: Service<Request<J>> + Send + 'static + Clone,
P: Backend<Request<J>> + 'static,
<S as Service<Request<J>>>::Future: Send,
<S as Service<Request<J>>>::Response: 'static,
<S as Service<Request<J>>>::Error: Send + Sync + 'static + Into<Box<dyn Error + Sync + Send>>,
<P as Backend<Request<J>>>::Stream: Unpin + Send + 'static,
sourcepub async fn run_with_signal<S>(self, signal: S) -> Result<(), Error>
pub async fn run_with_signal<S>(self, signal: S) -> Result<(), Error>
sourcepub async fn run(self) -> Result<(), Error>
pub async fn run(self) -> Result<(), Error>
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 exit forcefully.
source§impl<E> Monitor<E>
impl<E> Monitor<E>
sourcepub fn new() -> Monitor<E>where
E: Default,
pub fn new() -> Monitor<E>where
E: Default,
Creates a new monitor instance.
§Returns
A new monitor instance, with an empty collection of workers.
sourcepub fn new_with_executor(executor: E) -> Monitor<E>
pub fn new_with_executor(executor: E) -> Monitor<E>
Creates a new monitor instance with an executor
§Returns
A new monitor instance, with an empty collection of workers.
sourcepub fn set_executor<NE>(self, executor: NE) -> Monitor<NE>where
NE: Executor,
pub fn set_executor<NE>(self, executor: NE) -> Monitor<NE>where
NE: Executor,
Sets a custom executor for the monitor, allowing the usage of another runtime apart from Tokio.
The executor must implement the Executor
trait.
sourcepub fn shutdown_timeout(self, duration: Duration) -> Monitor<E>
pub fn shutdown_timeout(self, duration: Duration) -> Monitor<E>
sourcepub fn with_terminator(
self,
fut: impl Future<Output = ()> + Send + 'static
) -> Monitor<E>
pub fn with_terminator( self, fut: impl Future<Output = ()> + Send + 'static ) -> Monitor<E>
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§
Auto Trait Implementations§
impl<E> Freeze for Monitor<E>where
E: Freeze,
impl<E> !RefUnwindSafe for Monitor<E>
impl<E> Send for Monitor<E>where
E: Send,
impl<E> !Sync for Monitor<E>
impl<E> Unpin for Monitor<E>where
E: Unpin,
impl<E> !UnwindSafe for Monitor<E>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more