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.
Implementations§
Source§impl TaskScheduler
impl TaskScheduler
Sourcepub fn register(&mut self, task_id: u64, callable: ValueWord)
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.
Sourcepub fn take_callable(&mut self, task_id: u64) -> Option<ValueWord>
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.
Sourcepub fn complete(&mut self, task_id: u64, value: ValueWord)
pub fn complete(&mut self, task_id: u64, value: ValueWord)
Record a completed result for a task.
Sourcepub fn get_result(&self, task_id: u64) -> Option<&TaskStatus>
pub fn get_result(&self, task_id: u64) -> Option<&TaskStatus>
Get the result for a task, if it has completed.
Sourcepub fn is_resolved(&self, task_id: u64) -> bool
pub fn is_resolved(&self, task_id: u64) -> bool
Check whether a task has a stored result (completed or cancelled).
Sourcepub fn resolve_task<F>(
&mut self,
task_id: u64,
executor_fn: F,
) -> Result<ValueWord, VMError>
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.
Sourcepub fn resolve_task_group<F>(
&mut self,
kind: u8,
task_ids: &[u64],
executor_fn: F,
) -> Result<ValueWord, VMError>
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
impl Debug for TaskScheduler
Auto Trait Implementations§
impl Freeze for TaskScheduler
impl RefUnwindSafe for TaskScheduler
impl Send for TaskScheduler
impl Sync for TaskScheduler
impl Unpin for TaskScheduler
impl UnsafeUnpin for TaskScheduler
impl UnwindSafe for TaskScheduler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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