Skip to main content

DynLocalSpawnedTask

Trait DynLocalSpawnedTask 

Source
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§

Source

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 progress
  • executor - The local executor that owns this task, provided as a mutable reference to allow the task to spawn additional work
  • some_executor - Optional executor for spawning new Send tasks from within this task. Use None if spawning is not needed.
§Returns
  • Poll::Ready(()) when the task has completed
  • Poll::Pending when the task needs to be polled again later
Source

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.

Source

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.

Source

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.

Source

fn hint(&self) -> Hint

Returns the task’s execution hint.

Hints provide guidance to the executor about how to schedule the task, such as whether it’s CPU-intensive, I/O-bound, or has other special scheduling requirements.

Source

fn priority(&self) -> Priority

Returns the task’s priority.

Priority influences task scheduling order, with higher priority tasks typically being executed before lower priority ones, though the exact behavior depends on the executor implementation.

Implementors§

Source§

impl<'executor, F, ONotifier, Executor> DynLocalSpawnedTask<Executor> for SpawnedLocalTask<F, ONotifier, Executor>
where F: Future, Executor: SomeLocalExecutor<'executor>, ONotifier: ObserverNotified<F::Output>,