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: ValueWord)

Register a callable for a given task_id.

Called by op_spawn_task when a new task is spawned.

Source

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

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

Returns None if the task was already consumed or never registered.

Source

pub fn complete(&mut self, task_id: u64, value: ValueWord)

Record a completed result for a task.

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<ValueWord, String>>

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

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

Source

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

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

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

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<ValueWord, 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<ValueWord, 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 value, or an error.

The executor_fn callback receives the callable ValueWord and must execute it, returning the result.

Source

pub fn resolve_task_group<F>( &mut self, kind: u8, task_ids: &[u64], executor_fn: F, ) -> Result<ValueWord, 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.

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

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