Skip to main content

Module task_scheduler

Module task_scheduler 

Source
Expand description

Task scheduler for the async host runtime.

Manages spawned async tasks: stores their callables, tracks completion, and executes them (synchronously for now) when the VM suspends on an await.

The initial design runs tasks inline (synchronous execution at await-time). True concurrent execution via Tokio can be layered on later by changing resolve_task to spawn on the Tokio runtime.

§Wave 6.5 R-async-time / E-async surface follow-up

The pre-bulldozer scheduler stored callables and results as ValueWord and exposed an executor_fn: FnOnce(ValueWord) -> Result<ValueWord, _> callback for inline execution. ValueWord is deleted per ADR-006 §2.7 / CLAUDE.md “Forbidden Patterns”; the post-§2.7.7 carrier shape is the (bits: u64, kind: NativeKind) pair (the same shape pop_kinded() / push_kinded(...) thread through the typed VM stack — see playbook §3 canonical pattern). This file’s API now takes and returns kinded pairs end-to-end:

  • register(task_id, callable_bits, callable_kind)
  • take_callable(task_id) -> Option<(u64, NativeKind)>
  • complete(task_id, result_bits, result_kind)
  • register_external(task_id) -> oneshot::Sender<Result<(u64, NativeKind), String>>
  • resolve_task<F>(task_id, executor_fn) where F: FnOnce((u64, NativeKind)) -> Result<(u64, NativeKind), VMError>

Refcount discipline (playbook §3 drop discipline): every share stored in the scheduler’s maps owns one strong-count for heap-bearing kinds. take_callable, take_external_receiver, try_resolve_external, and Drop transfer that share to the caller (or release it). register, complete, and the cached-result paths in resolve_task / resolve_task_group use clone_with_kind when handing the share to a second consumer.

Out-of-territory callers (call_convention.rs::resolve_spawned_task, async_ops/mod.rs::op_await / op_spawn_task / op_join_await, gc_integration.rs::scan_roots) still reference deleted ValueWord-shape APIs; their migration is owned by separate sub-clusters and is out of R-async-time scope per playbook §10 dispatch protocol.

Structs§

TaskScheduler
Scheduler that tracks spawned async tasks by their future ID.

Enums§

TaskStatus
Completion status of a spawned task.