Skip to main content

Pipeline

Struct Pipeline 

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

Source

pub fn new<S, St>(st: St, service: impl IntoService<S, St, Req>) -> Self
where S: Service<St, Req, Res = Res, Error = Err> + 'static, St: 'static,

Creates a pipeline containing service and state.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn poll_shutdown(&self, cx: &mut Context<'_>) -> Poll<()>

Returns Ready when the service has been properly shut down.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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.

Trait Implementations§

Source§

impl<Req, Res, Err> Debug for Pipeline<Req, Res, Err>

Source§

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

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

impl<Req, Res, Err> Drop for Pipeline<Req, Res, Err>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<Req, Res, Err> ServiceCaller<Req, Res, Err> for Pipeline<Req, Res, Err>
where Req: 'static, Res: 'static, Err: 'static,

Source§

fn call_service(&self, req: Req) -> impl Future<Output = Result<Res, Err>>

Waits for readiness, then calls the service.

Auto Trait Implementations§

§

impl<Req, Res, Err> !RefUnwindSafe for Pipeline<Req, Res, Err>

§

impl<Req, Res, Err> !Send for Pipeline<Req, Res, Err>

§

impl<Req, Res, Err> !Sync for Pipeline<Req, Res, Err>

§

impl<Req, Res, Err> !UnwindSafe for Pipeline<Req, Res, Err>

§

impl<Req, Res, Err> Freeze for Pipeline<Req, Res, Err>

§

impl<Req, Res, Err> Unpin for Pipeline<Req, Res, Err>

§

impl<Req, Res, Err> UnsafeUnpin for Pipeline<Req, Res, Err>

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.