ChildBuilder

Struct ChildBuilder 

Source
pub struct ChildBuilder<'a, S = OneShot> { /* private fields */ }
Expand description

Builder for a yet-to-be-started child task.

This is the only way to configure a child: ChildSpecification, which this produces, carries no settings of its own. The builder uses the typestate pattern to expose only the properties that make sense for the child being described, so an invalid combination doesn’t need rejecting at runtime because it can’t be written down. Two axes govern that: whether the worker can be initialized more than once (which decides whether a restart policy is offered), and whether its policy lets it terminate for good (which decides whether it can be marked significant).

See BuilderState and CanTerminate for the states themselves.

Implementations§

Source§

impl<'a, S: BuilderState> ChildBuilder<'a, S>

Source

pub fn on_runtime(self, handle: Handle) -> Self

Runs this child task on a specific runtime.

Use this for compute-heavy work – encoding, serialization, protocol servers – that shouldn’t contend with the runtime driving the supervisor and its I/O. Only where the task runs changes: the child is still supervised here, and is still shut down and restarted by this supervisor.

Source

pub fn with_shutdown_timeout(self, timeout: Duration) -> Self

Sets an explicit shutdown timeout for this child task.

By default a closure-based child has no deadline of its own and is bounded only by the supervisor’s shutdown budget. Set this when the supervisor wants a particular child abandoned sooner than that – a deadline it is deliberately imposing, rather than a guess at how long the child ought to take. A value longer than the budget has no effect, since the two are resolved to whichever elapses first.

For a Supervisable child, this overrides the strategy the task reports for itself.

Source

pub fn with_shutdown_strategy(self, strategy: ShutdownStrategy) -> Self

Sets the explicit shutdown strategy used for this child task.

Source

pub fn with_budget_bounded_shutdown(self) -> Self

Gives this child no shutdown deadline of its own, leaving it bounded solely by the supervisor’s shutdown budget.

This is already the default for a closure-based child. A Supervisable child reports its own strategy, so this is how one opts into being bounded as part of the group instead – without which it silently keeps whatever Supervisable::shutdown_strategy returns, which may be far shorter than the budget.

See Supervisor::with_shutdown_budget for what the budget itself is.

Source

pub fn build(self) -> ChildSpecification<WorkerSpec>

Finishes describing the child without starting it, for Supervisor::add_worker.

Use this to register a configured child on a supervisor that hasn’t started yet; a child described this way is started when the supervisor runs, and restarted with it. spawn is the counterpart for a supervisor that is already running.

Whichever supervisor this builder was created against is irrelevant here – the child belongs to whichever one it is handed to.

Source

pub fn spawn(self) -> ChildId

Spawns the child.

Returns the child’s ChildId. The child is queued for the supervisor rather than started synchronously, so it may not be running yet by the time this returns; if the supervisor isn’t running, or shuts down before reaching the child, it never runs at all.

§Panics

If this builder targets the ambient supervisor and there isn’t one, this panics. See spawn.

Source§

impl<'a, S: CanTerminate> ChildBuilder<'a, S>

Source

pub fn with_significant(self, significant: bool) -> Self

Sets whether this child task’s termination should stop the supervisor.

Under AutoShutdown::AnySignificant – which is what a topology component’s supervisor uses – a significant child terminating shuts the supervisor down: the child is not individually restarted. That happens even when the child exits cleanly, so this suits a child the supervisor cannot function without, and not one that is expected to finish on its own.

For example, a component handling client connections generally shouldn’t stop just because one connection failed, but a component forwarding work to a child task may become inoperable if that task dies and cannot be reattached to the necessary channels or state without recreating the component.

Offered only for a child that can actually terminate for good – a one-shot child, or a supervisable one narrowed with transient or temporary. A permanent child is always restarted and so never reaches this path, which makes marking one significant a contradiction rather than a setting.

Defaults to false.

Source§

impl<'a> ChildBuilder<'a, Restartable>

Source

pub fn transient(self) -> ChildBuilder<'a, Terminable>

Restarts this child task only when it terminates abnormally.

A clean exit is taken at face value and the child stays stopped; a failure is restarted. Use this for work that has a natural end but whose failure means it never got there.

Narrows the restart policy to RestartType::Transient, which makes with_significant available: a child that can stop for good is one whose termination the supervisor may want to act on.

Source

pub fn temporary(self) -> ChildBuilder<'a, Terminable>

Never restarts this child task.

However it terminates – cleanly or by failing – the child stays stopped. Use this for work that is meant to run once, where a retry would be wrong rather than merely redundant.

Narrows the restart policy to RestartType::Temporary, which makes with_significant available: a child that can stop for good is one whose termination the supervisor may want to act on.

Auto Trait Implementations§

§

impl<'a, S> Freeze for ChildBuilder<'a, S>

§

impl<'a, S = OneShot> !RefUnwindSafe for ChildBuilder<'a, S>

§

impl<'a, S> Send for ChildBuilder<'a, S>
where S: Send,

§

impl<'a, S> Sync for ChildBuilder<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for ChildBuilder<'a, S>
where S: Unpin,

§

impl<'a, S = OneShot> !UnwindSafe for ChildBuilder<'a, S>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Track for T

§

fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>

Instruments this type by attaching the given resource group token, returning a Tracked wrapper. Read more
§

fn in_current_resource_group(self) -> Tracked<Self>

Instruments this type by attaching the current resource group, returning a Tracked wrapper. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more