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
impl BlockingExecutor
Sourcepub fn new(
policy: BlockingPoolPolicy,
owner_group: TaskGroup,
) -> Result<Self, RuntimeContractViolation>
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.
Sourcepub fn new_isolated(
policy: BlockingPoolPolicy,
owner_group: TaskGroup,
) -> Result<Self, RuntimeContractViolation>
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.
Sourcepub fn stop_admission(&self) -> RuntimeResult<()>
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.
Sourcepub async fn shutdown_until(
&self,
deadline: ShutdownDeadline,
) -> RuntimeResult<BlockingExecutorShutdownReport>
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.
Sourcepub fn try_drain_lease(
&self,
deadline: ShutdownDeadline,
max_operations: NonZeroUsize,
) -> RuntimeResult<BlockingDrainLease>
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.
Sourcepub fn policy(&self) -> &BlockingPoolPolicy
pub fn policy(&self) -> &BlockingPoolPolicy
Returns the policy.
Sourcepub fn spawn_io<F, R>(
&self,
name: impl Into<Arc<str>>,
operation: F,
) -> impl Future<Output = RuntimeResult<R>> + Send + '_
pub fn spawn_io<F, R>( &self, name: impl Into<Arc<str>>, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
Runs short blocking I/O with the preparation and polling behavior of Self::spawn.
Sourcepub fn spawn_io_until<F, R>(
&self,
name: impl Into<Arc<str>>,
deadline: ShutdownDeadline,
operation: F,
) -> impl Future<Output = RuntimeResult<R>> + Send + '_
pub fn spawn_io_until<F, R>( &self, name: impl Into<Arc<str>>, deadline: ShutdownDeadline, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
Runs short blocking I/O without admitting or waiting for work beyond deadline.
Sourcepub fn spawn<F, R>(
&self,
name: impl Into<Arc<str>>,
kind: BlockingKind,
operation: F,
) -> impl Future<Output = RuntimeResult<R>> + Send + '_
pub fn spawn<F, R>( &self, name: impl Into<Arc<str>>, kind: BlockingKind, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
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.
Sourcepub fn spawn_until<F, R>(
&self,
name: impl Into<Arc<str>>,
kind: BlockingKind,
deadline: ShutdownDeadline,
operation: F,
) -> impl Future<Output = RuntimeResult<R>> + Send + '_
pub fn spawn_until<F, R>( &self, name: impl Into<Arc<str>>, kind: BlockingKind, deadline: ShutdownDeadline, operation: F, ) -> impl Future<Output = RuntimeResult<R>> + Send + '_
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.
Sourcepub fn snapshot(&self) -> BlockingExecutorSnapshot
pub fn snapshot(&self) -> BlockingExecutorSnapshot
Returns the snapshot, including task names and individual elapsed times.
Sourcepub fn blocking_still_running(&self) -> usize
pub fn blocking_still_running(&self) -> usize
Returns the blocking still running.