pub struct Service<N, A, R>{ /* private fields */ }Expand description
The top-level orchestration handle.
See the crate-level documentation for architecture + lifecycle
diagram. Service owns the business-logic node and the peer / RPC
API adapters; driving start() runs the full lifecycle.
§Type parameters
N— theNodeLifecycleimplementation (the business core).A— thePeerApiimplementation. Use()for binaries that don’t serve a peer surface (daemon, wallet).R— theRpcApiimplementation. Use()for binaries that don’t serve RPC (introducer, relay).
Implementations§
Source§impl<N, A, R> Service<N, A, R>
impl<N, A, R> Service<N, A, R>
Sourcepub fn new(node: N, peer_api: A, rpc_api: R) -> Self
pub fn new(node: N, peer_api: A, rpc_api: R) -> Self
Construct a new service from its three components.
No runtime work happens here — ports are not bound, stores are not
opened. All of that runs inside start().
Sourcepub fn handle(&self) -> ServiceHandle
pub fn handle(&self) -> ServiceHandle
Return a cloneable handle for out-of-process-lifetime commands (signal handlers, RPC admin methods).
The returned handle remains valid after Service is dropped — its
operations simply become no-ops.
Sourcepub fn node(&self) -> &Arc<N>
pub fn node(&self) -> &Arc<N>
Borrow the node. Mostly useful in tests; production callers should
share state via the Arc<N> they constructed before Service::new.
Sourcepub fn shutdown_token(&self) -> &ShutdownToken
pub fn shutdown_token(&self) -> &ShutdownToken
Borrow the shutdown token. Use this to give background tasks a way to notice shutdown has been requested.
Sourcepub fn tasks(&self) -> &TaskRegistry
pub fn tasks(&self) -> &TaskRegistry
Borrow the task registry.
Sourcepub fn request_shutdown(&self, reason: ShutdownReason)
pub fn request_shutdown(&self, reason: ShutdownReason)
Request a graceful shutdown. Idempotent — only the first reason is recorded.
Sourcepub async fn start(self) -> Result<ExitStatus>
pub async fn start(self) -> Result<ExitStatus>
Drive the full lifecycle: pre_start → on_start → run → on_stop → post_stop. Returns once run exits (graceful or error) OR a
shutdown has been requested.
§Error handling
- A failure in
pre_startshort-circuits without calling any later hook. - A failure in
on_startcallspost_stopbut skipsrunandon_stop. - A failure in
runstill callson_stop+post_stop. - A failure in
on_stopis recorded but does not blockpost_stop. - Panics inside
runare caught viascopeguard-style drop logic and reported asExitReason::RunError.
Calling start twice on the same Service returns
ServiceError::AlreadyRunning.