Skip to main content

SpawnedLocalTask

Struct SpawnedLocalTask 

Source
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 type
  • ONotifier - The observer notification type for task completion
  • Executor - 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:

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

Source

pub fn hint(&self) -> Hint

Returns the execution hint for this spawned local task.

Source

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.

Source

pub fn priority(&self) -> Priority

Returns the priority of this spawned local task.

Source

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.

Source

pub fn task_id(&self) -> TaskID

Returns the unique identifier for this spawned local task.

Source

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>
where F: Future, ONotifier: ObserverNotified<F::Output>,

Source

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 execution
  • executor - The local executor that owns this task
  • some_executor - Optional executor for spawning Send tasks from within this task
§Task-Local Variables

During polling, the following task-local variables are set:

§Returns
  • Poll::Ready(()) when the task completes or is cancelled
  • Poll::Pending if the task needs to be polled again

Trait Implementations§

Source§

impl<F: Future, N, E> AsMut<F> for SpawnedLocalTask<F, N, E>

Source§

fn as_mut(&mut self) -> &mut F

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<F: Future, N, E> AsRef<F> for SpawnedLocalTask<F, N, E>

Source§

fn as_ref(&self) -> &F

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<F: Future, N, E> Debug for SpawnedLocalTask<F, N, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

fn poll<'ex>( self: Pin<&mut Self>, cx: &mut Context<'_>, executor: &'ex mut Executor, some_executor: Option<Box<dyn SomeExecutor<ExecutorNotifier = Infallible> + 'static>>, ) -> Poll<()>

Polls the task with its associated executor. Read more
Source§

fn poll_after(&self) -> Instant

Returns the earliest time this task should be polled. Read more
Source§

fn label(&self) -> &str

Returns the task’s label. Read more
Source§

fn hint(&self) -> Hint

Returns the task’s execution hint. Read more
Source§

fn priority(&self) -> Priority

Returns the task’s priority. Read more
Source§

fn task_id(&self) -> TaskID

Returns the task’s unique identifier. Read more

Auto Trait Implementations§

§

impl<F, ONotifier, Executor> Freeze for SpawnedLocalTask<F, ONotifier, Executor>
where F: Freeze, ONotifier: Freeze,

§

impl<F, ONotifier, Executor> !RefUnwindSafe for SpawnedLocalTask<F, ONotifier, Executor>

§

impl<F, ONotifier, Executor> Send for SpawnedLocalTask<F, ONotifier, Executor>
where F: Send, Executor: Send, ONotifier: Send, <F as Future>::Output: Send,

§

impl<F, ONotifier, Executor> Sync for SpawnedLocalTask<F, ONotifier, Executor>
where F: Sync, Executor: Sync, ONotifier: Sync, <F as Future>::Output: Send,

§

impl<F, ONotifier, Executor> Unpin for SpawnedLocalTask<F, ONotifier, Executor>
where F: Unpin, Executor: Unpin, ONotifier: Unpin,

§

impl<F, ONotifier, Executor> !UnwindSafe for SpawnedLocalTask<F, ONotifier, Executor>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.