Skip to main content

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 apply to the child that it describes. See BuilderState for the states.

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 method for compute-heavy work that must not compete with the runtime that drives its owner and its I/O. Examples are encoding, serialization, and protocol servers. This method changes only where the task runs. The owner of the child still supervises, shuts down, and restarts the child.

Source

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

Sets an explicit shutdown timeout for this child task.

A closure-based child defaults to five seconds, after which it is halted. Set this if a particular child needs more time to drain, or must be halted sooner. A timeout longer than its owner’s has no effect, since the child is halted along with its owner.

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 needed(self) -> Self

Marks this child as one that its owner cannot work without.

If the child stops without a request to stop and can only be started once, its owner also stops and fails. This occurs even when the child exits cleanly. Thus, use this method for a child that its owner cannot work without. Do not use it for a child that you expect to finish by itself. If the child can be started again, its owner restarts it after any such stop, not only after a failure.

For example, one failed connection is usually not a reason to stop a component that handles client connections. But a component that forwards work to a child task can become inoperable if that task stops unexpectedly. This occurs if the task cannot be attached again to the necessary channels or state unless the component is created again.

See the runtime documentation for the default.

Source

pub fn hosted(self) -> Self

Marks this child as one that its owner runs but does not need.

If the child stops without a request to stop, and its owner does not restart it, the owner reaps the child and continues. The owner does not restart a child that can only be started once, or a child that exited cleanly. If the child can be started again, its owner restarts it only if it failed, and accepts a clean exit as final. But if the child fails more often than the restart limit of its owner allows, the owner also fails, as for a needed child.

See the runtime documentation for the default.

Source

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

👎Deprecated:

mark the child needed instead, which stops its owner when it terminates for good

Sets whether the supervisor stops when this child task terminates.

This setting has an effect only under a supervisor that uses the deprecated with_auto_shutdown. It also has no effect on a child that its supervisor always restarts, such as a child that can start again and that you declare with Supervisor::add_worker without marking it hosted. The supervisor logs a warning for each child where the setting has no effect.

Source

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

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

Use this method to register a configured child on a supervisor that has not started yet. The supervisor starts this child when it runs. When the supervisor restarts, the child restarts with it. To start a child now, use spawn.

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.

A builder that was created from a SupervisorHandle spawns the child onto that supervisor. Other builders make the child a child of the current process, and the scope of that process holds it. See spawn.

Returns the ChildId of the child. This method queues the child and does not start it synchronously. Thus, when this method returns, the child can still be in the queue. If its owner does not run, or stops before it processes the child, the child never runs.

§Panics

Panics if this builder does not target a specific supervisor and code outside supervision calls this method. See spawn.

Source

pub fn spawn_sibling(self) -> ChildId

Spawns the child onto the ambient supervisor, the nearest supervisor above the current process.

The child is a sibling of the current process only if a supervisor runs that process directly. For a process that runs in a scope, the child goes to the nearest supervisor above it instead. See spawn_sibling.

A builder that was created from a SupervisorHandle spawns the child onto that supervisor, exactly as spawn does.

§Panics

Panics if this builder does not target a specific supervisor and there is no ambient supervisor.

Source

pub fn spawn_in(self, scope: &Scope) -> ChildId

Spawns the child into scope.

Source

pub fn spawn_or_detached(self) -> Option<ChildId>

Spawns the child into the scope of the current process, or as a detached task outside supervision.

Returns the ChildId of the child, or None if there was no current scope and the child started as a detached task instead. A detached child never receives a shutdown signal, and nothing restarts it or waits for it. This is how the same work runs without supervision at all. Thus, this method is the correct choice for code that can be called from any location, such as a primitive that a test can construct.

Source§

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

Source

pub fn transient(self) -> Self

👎Deprecated:

mark the child hosted instead, which restarts it only if it fails

Restarts this child task only when it terminates abnormally.

Source

pub fn temporary(self) -> Self

👎Deprecated:

implement Supervisable::can_restart instead, if the child can only be started once

Never restarts this child task.

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> UnsafeUnpin for ChildBuilder<'a, S>

§

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