Skip to main content

BlockingExecutor

Struct BlockingExecutor 

Source
pub struct BlockingExecutor { /* private fields */ }
Expand description

Runs short blocking work through a bounded lane and one root-owned global admission budget.

Cloning this value shares queue state and capacity; it never creates a new owner. Execution always uses the injected owner’s Tokio runtime, including when the submission future is polled by a different runtime. Cancellation while queued removes the task immediately. Cancellation or timeout after execution begins leaves the admission permit inside the actual blocking closure, so capacity is released only when that closure exits.

Implementations§

Source§

impl BlockingExecutor

Source

pub fn new( policy: BlockingPoolPolicy, owner_group: TaskGroup, ) -> Result<Self, RuntimeContractViolation>

Creates an isolated executor through Self::new_isolated.

§Errors

Returns a contract violation when policy is invalid.

Source

pub fn new_isolated( policy: BlockingPoolPolicy, owner_group: TaskGroup, ) -> Result<Self, RuntimeContractViolation>

Creates an isolated executor for tests and adapters.

Production components use the managed lanes of a ChildServiceContext, which share one global budget. This executor instead has its own exact capacity and task table, outside the managed lanes and their diagnostics. owner_group supplies its runtime and admission scope, and the executor is registered with that group’s tree: a closure still running when the tree’s owner assembles a shutdown report is counted in blocking_still_running, so the report is not healthy while that work can still have side effects.

§Errors

Returns a contract violation when policy is invalid.

Source

pub fn stop_admission(&self) -> RuntimeResult<()>

Stops admission to this isolated executor and wakes its queued submissions.

All clones share this gate. The supplied task group and other executors remain open. Already admitted closures continue to own their permits.

§Errors

Returns an unsupported-operation error for a managed lane; its service context owns admission and shutdown.

Source

pub async fn shutdown_until( &self, deadline: ShutdownDeadline, ) -> RuntimeResult<BlockingExecutorShutdownReport>

Stops this isolated executor and asynchronously waits for owned work.

The caller’s deadline bounds waiting, not execution of already-running closures. An incomplete report retains their counts. This method does not block the calling thread or close the supplied task group.

§Errors

Returns an unsupported-operation error for a managed lane.

Source

pub fn try_drain_lease( &self, deadline: ShutdownDeadline, max_operations: NonZeroUsize, ) -> RuntimeResult<BlockingDrainLease>

Reserves a bounded blocking-I/O allowance for work already accepted by this executor’s service scope, or for that owner’s finalization slot.

The scope must still be open when the lease is created. The lease never extends deadline or a shutdown deadline later installed on its scope, and its non-zero submission allowance is shared if the lease is moved through application-owned shutdown code.

§Errors

Returns an unavailable failure when this executor is unscoped or its scope is no longer open, and a timeout failure when deadline expired.

Source

pub fn policy(&self) -> &BlockingPoolPolicy

Returns the policy.

Source

pub fn spawn_io<F, R>( &self, name: impl Into<Arc<str>>, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Runs short blocking I/O with the preparation and polling behavior of Self::spawn.

Source

pub fn spawn_io_until<F, R>( &self, name: impl Into<Arc<str>>, deadline: ShutdownDeadline, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Runs short blocking I/O without admitting or waiting for work beyond deadline.

Source

pub fn spawn<F, R>( &self, name: impl Into<Arc<str>>, kind: BlockingKind, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Spawns the supplied task.

Converts the name and boxes the closure immediately to keep large captures out of the returned future. Admission and submission begin only when that future is polled.

Source

pub fn spawn_until<F, R>( &self, name: impl Into<Arc<str>>, kind: BlockingKind, deadline: ShutdownDeadline, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
where F: FnOnce() -> R + Send + 'static, R: Send + 'static,

Runs blocking work with one absolute deadline for admission and waiting.

Expiry stops waiting; an already running closure retains its capacity until it exits and may still produce side effects.

Source

pub fn snapshot(&self) -> BlockingExecutorSnapshot

Returns the snapshot, including task names and individual elapsed times.

Source

pub fn blocking_still_running(&self) -> usize

Returns the blocking still running.

Trait Implementations§

Source§

impl Clone for BlockingExecutor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockingExecutor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
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