pub struct ServiceGroup { /* private fields */ }Expand description
A group of async services that start together and stop together.
Services are started concurrently. Like go-zero’s service group, startup order must not be relied on. When a process shutdown signal, explicit handle stop, or service error occurs, the group broadcasts a shutdown token, runs stop hooks, waits for tasks and returns aggregated errors if any.
Implementations§
Source§impl ServiceGroup
impl ServiceGroup
Sourcepub fn with_config(config: ServiceGroupConfig) -> Self
pub fn with_config(config: ServiceGroupConfig) -> Self
Creates an empty service group with custom controls.
Sourcepub fn add<S>(&mut self, service: S) -> &mut Selfwhere
S: Service,
pub fn add<S>(&mut self, service: S) -> &mut Selfwhere
S: Service,
Adds a service to the group.
Sourcepub fn add_arc<S>(&mut self, service: Arc<S>) -> &mut Selfwhere
S: Service,
pub fn add_arc<S>(&mut self, service: Arc<S>) -> &mut Selfwhere
S: Service,
Adds an already shared service to the group.
Sourcepub fn add_fn<F, Fut>(&mut self, name: impl Into<String>, start: F) -> &mut Selfwhere
F: Fn(ShutdownToken) -> Fut + Send + Sync + 'static,
Fut: Future<Output = CoreResult<()>> + Send + 'static,
pub fn add_fn<F, Fut>(&mut self, name: impl Into<String>, start: F) -> &mut Selfwhere
F: Fn(ShutdownToken) -> Fut + Send + Sync + 'static,
Fut: Future<Output = CoreResult<()>> + Send + 'static,
Adds a service backed by an async start function.
Sourcepub fn handle(&self) -> ServiceGroupHandle
pub fn handle(&self) -> ServiceGroupHandle
Returns a handle that can stop the group while it is running.
Sourcepub async fn start(self) -> CoreResult<()>
pub async fn start(self) -> CoreResult<()>
Starts all services and waits for Ctrl-C or explicit stop.
Sourcepub async fn start_with_shutdown<F>(self, shutdown: F) -> CoreResult<()>
pub async fn start_with_shutdown<F>(self, shutdown: F) -> CoreResult<()>
Starts all services and waits for the supplied shutdown future.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ServiceGroup
impl !RefUnwindSafe for ServiceGroup
impl Send for ServiceGroup
impl Sync for ServiceGroup
impl Unpin for ServiceGroup
impl UnsafeUnpin for ServiceGroup
impl !UnwindSafe for ServiceGroup
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request