pub struct SpawnedLocalTask<F, ONotifier, Executor>where
F: Future,{ /* private fields */ }Expand description
A task that has been spawned onto a local executor.
SpawnedLocalTask is similar to SpawnedTask but designed for executors that
are not Send and are tied to a specific thread. Unlike SpawnedTask, this type
does not implement Future directly because local executors need to be injected
during each poll operation.
§Type Parameters
F- The underlying future typeONotifier- The observer notification type for task completionExecutor- The local executor type that spawned this task
§Design Note
Unlike SpawnedTask which embeds a copy of the executor, SpawnedLocalTask only
stores a PhantomData marker. This is because local executors may be implemented
as references that cannot be stored. Instead, the executor must be provided explicitly
when polling the task.
§Task-Local Context
When polled via poll, this task sets up the same task-local
variables as SpawnedTask, with the addition of:
crate::task::TASK_LOCAL_EXECUTOR- Reference to the local executor
§Examples
Local tasks must be polled explicitly with a reference to their executor:
use some_executor::task::SpawnedLocalTask;
use std::pin::Pin;
// Poll the local task with its executor
let poll_result = Pin::new(&mut spawned).poll(&mut context, &mut executor, None);Implementations§
Source§impl<F: Future, ONotifier, Executor> SpawnedLocalTask<F, ONotifier, Executor>
impl<F: Future, ONotifier, Executor> SpawnedLocalTask<F, ONotifier, Executor>
Sourcepub fn label(&self) -> &str
pub fn label(&self) -> &str
Returns the label of this spawned local task.
§Panics
Panics if called while the task is being polled, as the label is temporarily moved into task-local storage during polling.
Sourcepub fn poll_after(&self) -> Instant
pub fn poll_after(&self) -> Instant
Returns the earliest time this task should be polled.
Executors should respect this time and not poll the task before it.
Sourcepub fn into_future(self) -> F
pub fn into_future(self) -> F
Consumes the spawned local task and returns the underlying future.
This is useful if you need to extract the future from the spawned task wrapper, but note that you’ll lose the task metadata and observer infrastructure.
Source§impl<'executor, F, ONotifier, Executor: SomeLocalExecutor<'executor>> SpawnedLocalTask<F, ONotifier, Executor>
impl<'executor, F, ONotifier, Executor: SomeLocalExecutor<'executor>> SpawnedLocalTask<F, ONotifier, Executor>
Sourcepub fn poll(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
executor: &mut Executor,
some_executor: Option<Box<dyn SomeExecutor<ExecutorNotifier = Infallible> + 'static>>,
) -> Poll<()>
pub fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, executor: &mut Executor, some_executor: Option<Box<dyn SomeExecutor<ExecutorNotifier = Infallible> + 'static>>, ) -> Poll<()>
Polls the spawned local task to advance its execution.
Unlike SpawnedTask which implements Future, local tasks must be polled
explicitly with their executor. This is because local executors may be
implemented as references that cannot be stored.
§Arguments
cx- The waker context for async executionexecutor- The local executor that owns this tasksome_executor- Optional executor for spawning Send tasks from within this task
§Task-Local Variables
During polling, the following task-local variables are set:
TASK_LABEL- The task’s labelTASK_ID- The task’s unique identifierTASK_PRIORITY- The task’s priorityIS_CANCELLED- Cancellation statuscrate::task::TASK_LOCAL_EXECUTOR- Reference to the provided local executorTASK_EXECUTOR- Reference to the Send executor (if provided)
§Returns
Poll::Ready(())when the task completes or is cancelledPoll::Pendingif the task needs to be polled again