pub struct Pipeline<Req, Res, Err> { /* private fields */ }Expand description
Execution container for a service and its state.
A pipeline coordinates readiness, calls, and shutdown for the enclosed
service chain.
Successful readiness is shared by every binding until a subscribed
crate::ReadyNotifier invalidates it. Calls do not consume readiness.
Shutdown is advisory: it shuts down the enclosed service, but does not
reject later calls. Readiness checks return Ok(()) once shutdown has
started, and calls are still forwarded to the service. Callers that must
stop admitting work check Pipeline::is_shutdown.
Implementations§
Source§impl<Req, Res, Err> Pipeline<Req, Res, Err>where
Req: 'static,
Res: 'static,
Err: 'static,
impl<Req, Res, Err> Pipeline<Req, Res, Err>where
Req: 'static,
Res: 'static,
Err: 'static,
Sourcepub fn new<S, St>(st: St, service: impl IntoService<S, St, Req>) -> Selfwhere
S: Service<St, Req, Res = Res, Error = Err> + 'static,
St: 'static,
pub fn new<S, St>(st: St, service: impl IntoService<S, St, Req>) -> Selfwhere
S: Service<St, Req, Res = Res, Error = Err> + 'static,
St: 'static,
Creates a pipeline containing service and state.
Sourcepub fn ready(&self) -> impl Future<Output = Result<(), Err>>
pub fn ready(&self) -> impl Future<Output = Result<(), Err>>
Returns when the pipeline is ready to process requests.
Reuses valid shared readiness without allocating a readiness future.
Cancelling the active caller drops its check and lets another waiter
take ownership. Returns successfully if pipeline shutdown has started,
like Self::poll_ready.
The first caller that finds readiness invalid runs the shared check in its own future, and other waiters wait for it. Like a held lock, a pending future must be polled or dropped: keeping it alive without polling stalls every other readiness waiter on this pipeline.
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Returns true while the pipeline’s shared readiness is valid.
Does not run or register a readiness check. false means readiness is
unknown or was invalidated, not that the service is not ready.
Sourcepub fn call(&self, req: Req) -> impl Future<Output = Result<Res, Err>>
pub fn call(&self, req: Req) -> impl Future<Output = Result<Res, Err>>
Waits for readiness, then calls the service.
Reuses valid shared readiness without consuming it. Calls are forwarded
even after shutdown has started; see Pipeline.
Sourcepub fn call_static(&self, req: Req) -> PipelineCall<Req, Res, Err> ⓘ
pub fn call_static(&self, req: Req) -> PipelineCall<Req, Res, Err> ⓘ
Returns an owned future that waits for readiness and calls the service.
Unlike Pipeline::call, the returned future does not borrow the
pipeline and can be moved between local tasks. Shared readiness is
consulted when the future is polled and the call is dispatched, not
when the future is constructed.
Sourcepub fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Err>>
pub fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Err>>
Returns Ready when the pipeline is ready to process requests.
Registers the task for readiness changes and reuses valid shared readiness. A pending check is retained by the pipeline, even if this task stops polling; other callers can continue driving it. The retained check and its wake sources run on this pipeline’s thread. Its checker wakers must also be finally dropped on that thread, even after the pipeline is dropped; foreign wakes or final drops panic.
Sourcepub fn poll_shutdown(&self, cx: &mut Context<'_>) -> Poll<()>
pub fn poll_shutdown(&self, cx: &mut Context<'_>) -> Poll<()>
Returns Ready when the service has been properly shut down.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Checks whether pipeline shutdown has been initiated.
The pipeline does not reject calls after shutdown; callers use this to stop admitting new work.
Sourcepub fn shutdown(&self) -> impl Future<Output = ()>
pub fn shutdown(&self) -> impl Future<Output = ()>
Shuts down the enclosed service.
Marks the pipeline as shutting down, then waits for the service’s
shutdown. Later calls are not rejected; see Pipeline.
Sourcepub fn bind(&self) -> PipelineBinding<Req, Res, Err>
pub fn bind(&self) -> PipelineBinding<Req, Res, Err>
Creates a new binding to this pipeline.
The binding can be used to check readiness and call the service.
Sourcepub fn on_notify(&self, callback: &ReadyCallback)
pub fn on_notify(&self, callback: &ReadyCallback)
Registers a callback for notifications reaching this pipeline’s scope.
Registration is shared with all bindings and persists until the scope
is dropped. Repeated registration of the same handle is idempotent.
The callback receives 0 for this root scope.
See ReadyCallback for notification semantics.
Sourcepub fn bind_to(&self, ctx: &BindCtx<'_>)
pub fn bind_to(&self, ctx: &BindCtx<'_>)
Registers this pipeline as a readiness dependency of the enclosing service.
Call from Service::bind so changes to this pipeline’s readiness also
invalidate the enclosing scope. Repeated registration is idempotent and
does not rebind the inner service or create another runtime handle.
Sourcepub fn readiness_link(&self) -> ReadyLink
pub fn readiness_link(&self) -> ReadyLink
Returns an explicit, non-owning endpoint for this pipeline’s readiness.
Register with BindCtx::subscribe_pipeline, or use Self::bind_to
as shorthand. All pipeline bindings share the same endpoint.