pub trait ExecutorControl:
Send
+ Sync
+ 'static {
// Required methods
fn block_on<F>(&self, future: F) -> F::Output
where F: Future;
fn try_run(&self) -> bool;
fn shutdown(&self);
fn shutdown_timeout(&self, timeout: Duration);
fn is_shutting_down(&self) -> bool;
fn worker_count(&self) -> usize;
fn load(&self) -> usize;
}Expand description
Provides control operations for executor lifecycle management.
This trait enables external systems to manage executor state transitions, perform health checks, and coordinate shutdown procedures.
Required Methods§
Sourcefn block_on<F>(&self, future: F) -> F::Outputwhere
F: Future,
fn block_on<F>(&self, future: F) -> F::Outputwhere
F: Future,
Block the current thread until the future completes.
§Behavior Guarantees
- Blocks calling thread until future resolves
- Supports nested async operations within the future
- Handles panic propagation from the future
- May deadlock if future depends on blocked thread
§Performance Characteristics
- Optimal for CPU-bound futures with minimal I/O
- May block calling thread indefinitely
- Memory: Future size + execution context
- Suitable for main thread or dedicated blocking contexts
Sourcefn try_run(&self) -> bool
fn try_run(&self) -> bool
Attempt to run tasks without blocking.
§Behavior Guarantees
- Non-blocking operation, returns immediately
- Returns true if any work was performed
- May perform multiple task executions in single call
- Suitable for integration with external event loops
§Performance Characteristics
- O(1) operation, < 1μs typical latency
- Work stealing: Attempts to balance load across threads
- Suitable for event loops requiring non-blocking progress
Sourcefn shutdown(&self)
fn shutdown(&self)
Shutdown the executor gracefully.
§Behavior Guarantees
- Allows running tasks to complete naturally
- Prevents new tasks from being spawned
- Idempotent operation - safe to call multiple times
- Blocks until all worker threads have stopped
- Releases all resources and thread handles
§Performance Characteristics
- Shutdown time: Depends on longest running task
- Resource cleanup: All memory and handles released
- Thread coordination: Uses efficient signaling
Sourcefn shutdown_timeout(&self, timeout: Duration)
fn shutdown_timeout(&self, timeout: Duration)
Shutdown the executor with a timeout.
§Behavior Guarantees
- Attempts graceful shutdown first
- Forces termination after timeout expires
- May result in task cancellation or abortion
- Guarantees executor stops within timeout + small overhead
§Performance Characteristics
- Graceful phase: Same as
shutdown() - Forced phase: Immediate thread termination
- Timeout accuracy: ±10ms typical variance
Sourcefn is_shutting_down(&self) -> bool
fn is_shutting_down(&self) -> bool
Check if the executor is shutting down.
§Behavior Guarantees
- Returns true once shutdown has been initiated
- Eventually consistent across all threads
- Remains true until executor is fully stopped
§Performance Characteristics
- O(1) operation, < 10ns latency
- Non-blocking atomic read operation
- Memory ordering: Acquire semantics
Sourcefn worker_count(&self) -> usize
fn worker_count(&self) -> usize
Sourcefn load(&self) -> usize
fn load(&self) -> usize
Get the current load (number of pending tasks).
§Behavior Guarantees
- Returns approximate pending task count
- Eventually consistent across distributed queues
- May include tasks currently being executed
- Does not include blocked or suspended tasks
§Performance Characteristics
- O(1) operation for local queues
- May involve atomic reads across threads
- Latency: < 100ns typical
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".