Skip to main content

TaskScheduler

Struct TaskScheduler 

Source
pub struct TaskScheduler { /* private fields */ }
Expand description

Scheduler that tracks spawned async tasks by their future ID.

The VM’s SpawnTask opcode registers a callable here. When the VM later suspends on WaitType::Future { id }, the host looks up the callable, executes it, and stores the result so the VM can resume.

Supports both inline tasks (callable executed synchronously at await-time) and external tasks (completed by background Tokio tasks via oneshot channels).

Implementations§

Source§

impl TaskScheduler

Source

pub fn new() -> Self

Create a new, empty scheduler.

Source

pub fn register( &mut self, task_id: u64, callable_bits: u64, callable_kind: NativeKind, )

Register a callable for a given task_id.

Called by op_spawn_task when a new task is spawned. The caller transfers one strong-count share for the kinded pair into the scheduler; on take_callable (or Drop) the share transfers back out (or is released).

Source

pub fn take_callable(&mut self, task_id: u64) -> Option<(u64, NativeKind)>

Take (remove) the callable for task_id so it can be executed.

Returns None if the task was already consumed or never registered. Ownership of the kinded pair transfers to the caller.

Source

pub fn complete( &mut self, task_id: u64, value_bits: u64, value_kind: NativeKind, )

Record a completed result for a task.

The caller transfers one strong-count share into the scheduler. If a completion was already recorded, the prior share is released.

Source

pub fn cancel(&mut self, task_id: u64)

Mark a task as cancelled.

Source

pub fn get_result(&self, task_id: u64) -> Option<&TaskStatus>

Get the result for a task, if it has completed.

Source

pub fn is_resolved(&self, task_id: u64) -> bool

Check whether a task has a stored result (completed or cancelled).

Source

pub fn register_external( &mut self, task_id: u64, ) -> Sender<Result<(u64, NativeKind), String>>

Register an externally-completed task (e.g., remote call).

Returns a oneshot::Sender that the background task uses to deliver the result (kinded pair). The scheduler marks the task as Pending and stores the receiver.

Source

pub fn try_resolve_external( &mut self, task_id: u64, ) -> Option<Result<(u64, NativeKind), VMError>>

Try to resolve an external task (non-blocking check).

Returns Some(Ok((bits, kind))) if the external task completed successfully, Some(Err(..)) on error/cancellation, or None if still pending.

On the cached-completion fast path, the cached share is cloned (clone_with_kind) so both the scheduler entry and the returned pair own independent shares — caller drops/uses freely.

Source

pub fn has_external(&self, task_id: u64) -> bool

Check whether a task has an external receiver (is externally-completed).

Source

pub fn take_external_receiver( &mut self, task_id: u64, ) -> Option<Receiver<Result<(u64, NativeKind), String>>>

Take the external receiver for async awaiting.

Used by execute_with_async when it needs to truly .await an external task’s completion.

Source

pub fn resolve_task<F>( &mut self, task_id: u64, executor_fn: F, ) -> Result<(u64, NativeKind), VMError>

Resolve a single task by executing its callable on a fresh VM executor.

This is the synchronous (inline) strategy: the callable is executed immediately when awaited. Returns the result kinded pair, or an error.

The executor_fn callback receives the callable kinded pair and must execute it, returning the result kinded pair. Ownership of the pair transfers into the callback; the callback’s returned pair owns one share which is then cached and a clone returned to the caller.

Source

pub fn resolve_task_group<F>( &mut self, kind: u8, task_ids: &[u64], executor_fn: F, ) -> Result<(u64, NativeKind), VMError>

Resolve a task group according to the join strategy.

Join kinds (encoded in the high 2 bits of JoinInit’s packed operand): 0 = All — wait for all tasks, return array of results 1 = Race — return first completed result 2 = Any — return first successful result (skip errors) 3 = AllSettled — return array of {status, value/error} for every task

Since we execute synchronously, “race” and “any” still run all tasks sequentially but return early on the first applicable result.

Returned aggregate is a TaskGroup-shaped heap value (Arc) holding the constituent task ids; the caller pushes the kinded pair onto the stack with NativeKind::Ptr(HeapKind::TaskGroup). (The pre-bulldozer code returned a heap array of kinded results; without a kinded VMArray helper post-§2.7.4, the TaskGroup carrier is the minimum shape the await-time decoder can re-walk.)

Trait Implementations§

Source§

impl Debug for TaskScheduler

Source§

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

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

impl Default for TaskScheduler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for TaskScheduler

Source§

fn drop(&mut self)

Release every heap-bearing share the scheduler still owns.

Required to honor the §2.7.7 retain-on-store contract: every value inserted via register / complete carries a strong-count share; if the scheduler is dropped before consumers retire those shares, drop_with_kind releases them here.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more