ChildBuilder

Struct ChildBuilder 

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

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

Advanced properties of a task can be configured with this builder prior to spawning. This builder uses the typestate pattern to control which properties of the child task that can be configured (by controlling which configuration methods are exposed) based on whether the worker is supervisable or not.

See BuilderState for more information on worker types.

Implementations§

Source§

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

Source

pub fn on_worker_pool(self) -> Self

Runs this child task on the shared worker pool owned by the topology, instead of the component’s runtime.

Use this for compute-heavy work – encoding, serialization, protocol servers – that shouldn’t contend with the runtime that drives the supervisors and I/O for the topology.

Source

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

Runs this child task on a specific runtime.

Prefer on_worker_pool unless the component owns a runtime of its own.

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 component’s shutdown budget. Set this when the component 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_significant(self, significant: bool) -> Self

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

A component’s supervisor uses AutoShutdown::AnySignificant, so a significant child terminating shuts the component down: the child is not individually restarted. That happens even when the child exits cleanly, so this suits a child the component 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.

Only meaningful for a child that can terminate without being restarted, so setting it alongside RestartType::Permanent has no effect: such a child is always restarted and so never reaches this path.

Defaults to false.

Source

pub async fn spawn(self) -> Result<ChildId, SpawnError>

Spawns the child, returning once the supervisor has started it.

§Errors

Returns SpawnError::SupervisorGone if the component’s supervisor isn’t running, or SpawnError::Rejected if it rejected the child (for example, an invalid name). A component’s supervisor is running for the whole of the component’s run, so SupervisorGone in a component indicates that the topology is already being torn down.

Source§

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

Source

pub fn with_restart_type(self, restart_type: RestartType) -> Self

Sets the restart type for this child task.

Supervised tasks that are defined through Supervisable default to being restarted permanently, since their structure naturally exposes a mechanism to allow initializing a worker more than once. However, in some cases, it may be desirable to disallow restarting a specific worker and instead treat their exit differently: only restart when the worker exits abnormally, or never restart the worker, and so on.

Defaults to RestartType::Permanent.

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