pub struct ExecutorDrain { /* private fields */ }Expand description
A future that completes when all tasks in an executor have finished.
ExecutorDrain is returned by Executor::drain_async() and implements
Future<Output = ()>. It polls the executor’s internal state to determine
when all tasks have completed execution.
§Examples
use some_global_executor::Executor;
use some_executor::SomeExecutor;
use some_executor::task::{Task, Configuration};
let mut executor = Executor::new("async-drain".to_string(), 2);
// Spawn some work
let task = Task::without_notifications(
"work".to_string(),
Configuration::default(),
async {
// Simulate some work
42
}
);
executor.spawn(task);
// In async context, you would use:
// executor.drain_async().await;
// Here we use synchronous drain for the example
executor.drain();Trait Implementations§
Source§impl AsMut<Executor> for ExecutorDrain
Provides mutable access to the underlying Executor from an ExecutorDrain.
impl AsMut<Executor> for ExecutorDrain
Provides mutable access to the underlying Executor from an ExecutorDrain.
This allows operations like resizing the thread pool even while draining.
§Examples
use some_global_executor::{Executor, ExecutorDrain};
let executor = Executor::new("test".to_string(), 2);
let mut drain = executor.drain_async();
drain.as_mut().resize(4); // Resize while drainingSource§impl AsRef<Executor> for ExecutorDrain
Provides immutable access to the underlying Executor from an ExecutorDrain.
impl AsRef<Executor> for ExecutorDrain
Provides immutable access to the underlying Executor from an ExecutorDrain.
§Examples
use some_global_executor::{Executor, ExecutorDrain};
let executor = Executor::new("test".to_string(), 2);
let drain = executor.drain_async();
let name = drain.as_ref().name();
assert_eq!(name, "test");Source§impl Debug for ExecutorDrain
impl Debug for ExecutorDrain
Source§impl From<Executor> for ExecutorDrain
Converts an Executor into an ExecutorDrain future.
impl From<Executor> for ExecutorDrain
Converts an Executor into an ExecutorDrain future.
This conversion is equivalent to calling Executor::drain_async().
§Examples
use some_global_executor::{Executor, ExecutorDrain};
let executor = Executor::new("test".to_string(), 2);
let drain: ExecutorDrain = executor.into();
// In async context: drain.await;
// For this example, convert back and drain:
let executor: Executor = drain.into();
executor.drain();Source§impl From<ExecutorDrain> for Executor
Converts an ExecutorDrain back to its underlying Executor.
impl From<ExecutorDrain> for Executor
Converts an ExecutorDrain back to its underlying Executor.
This is useful when you need to access the executor after initiating a drain operation but before it completes.
§Examples
use some_global_executor::{Executor, ExecutorDrain};
let executor = Executor::new("test".to_string(), 2);
let drain: ExecutorDrain = executor.into();
let executor: Executor = drain.into();
executor.drain();