pub trait DynLocalSpawnedTask<Executor> {
// Required methods
fn poll<'executor>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
executor: &'executor mut Executor,
some_executor: Option<Box<dyn SomeExecutor<ExecutorNotifier = Infallible> + 'static>>,
) -> Poll<()>;
fn poll_after(&self) -> Instant;
fn label(&self) -> &str;
fn task_id(&self) -> TaskID;
fn hint(&self) -> Hint;
fn priority(&self) -> Priority;
}Expand description
Object-safe type-erased wrapper for SpawnedLocalTask.
This trait allows executors to work with spawned local tasks without knowing their concrete future type. It provides all the essential operations needed to poll and query task metadata in a type-erased manner.
§Purpose
DynLocalSpawnedTask enables executors to manage collections of local (non-Send) tasks
with different future types. This is particularly important for single-threaded executors
that need to work with futures containing Rc, RefCell, or other !Send types.
§Type Parameters
Executor- The type of the local executor that will poll this task. This allows the task to be aware of its executor type while maintaining type erasure for the future itself.
§Usage in Custom Executors
This trait is primarily used internally by executors that need to store heterogeneous
collections of local tasks. The trait methods mirror those of SpawnedLocalTask.
§Example
use std::pin::Pin;
use some_executor::task::DynLocalSpawnedTask;
// Custom local executor storing type-erased tasks
struct CustomLocalExecutor<'future> {
tasks: Vec<Pin<Box<dyn DynLocalSpawnedTask<CustomLocalExecutor<'future>> + 'future>>>,
}§Implementation
This trait is automatically implemented for all SpawnedLocalTask instances where
the future, executor, and notifier types satisfy the appropriate bounds.
Required Methods§
Sourcefn poll<'executor>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
executor: &'executor mut Executor,
some_executor: Option<Box<dyn SomeExecutor<ExecutorNotifier = Infallible> + 'static>>,
) -> Poll<()>
fn poll<'executor>( self: Pin<&mut Self>, cx: &mut Context<'_>, executor: &'executor mut Executor, some_executor: Option<Box<dyn SomeExecutor<ExecutorNotifier = Infallible> + 'static>>, ) -> Poll<()>
Polls the task with its associated executor.
This method advances the task’s future and manages task-local variables during execution. It should be called by the executor’s main polling loop.
§Arguments
cx- The waker context for async execution, containing the waker that will be notified when the task is ready to make progressexecutor- The local executor that owns this task, provided as a mutable reference to allow the task to spawn additional worksome_executor- Optional executor for spawning new Send tasks from within this task. UseNoneif spawning is not needed.
§Returns
Poll::Ready(())when the task has completedPoll::Pendingwhen the task needs to be polled again later
Sourcefn poll_after(&self) -> Instant
fn poll_after(&self) -> Instant
Returns the earliest time this task should be polled.
This can be used by executors to implement delayed task execution or
timer-based scheduling. Tasks with a future poll_after time should
not be polled until that time has passed.
Sourcefn label(&self) -> &str
fn label(&self) -> &str
Returns the task’s label.
The label is a human-readable identifier for the task, useful for debugging, logging, and monitoring task execution.
Sourcefn task_id(&self) -> TaskID
fn task_id(&self) -> TaskID
Returns the task’s unique identifier.
Each task has a globally unique ID that can be used for tracking, correlation, and debugging purposes.