pub struct AsyncScheduler { /* private fields */ }
Expand description
Implementations§
Trait Implementations§
Source§impl Runnable for AsyncScheduler
impl Runnable for AsyncScheduler
Source§fn step(&mut self, gc: &mut GC<OnionObjectCell>) -> StepResult
fn step(&mut self, gc: &mut GC<OnionObjectCell>) -> StepResult
执行一个调度步骤
这是调度器的核心方法,负责遍历任务队列并按优先级调度执行任务。 每次调用会增加步数计数器,并检查每个任务是否应该在当前步执行。
§参数
gc
- 垃圾收集器的可变引用,用于内存管理
§返回值
StepResult::Continue
- 还有任务需要继续执行StepResult::Return(_)
- 所有任务完成,返回主任务的结果StepResult::Error(_)
- 执行过程中出现错误
§调度逻辑
- 检查队列是否为空,为空则返回主任务结果
- 增加步数计数器
- 遍历队列中的每个任务
- 根据任务优先级和当前步数决定是否执行
- 处理任务执行结果:完成、继续、挂起或错误
- 动态调整任务优先级和队列位置
Source§fn receive(
&mut self,
_step_result: &StepResult,
_gc: &mut GC<OnionObjectCell>,
) -> Result<(), RuntimeError>
fn receive( &mut self, _step_result: &StepResult, _gc: &mut GC<OnionObjectCell>, ) -> Result<(), RuntimeError>
Source§fn format_context(&self) -> String
fn format_context(&self) -> String
格式化调度器的当前上下文信息
生成包含调度器状态和所有任务详细信息的格式化字符串, 用于调试和监控调度器的运行状态。
§返回值
返回包含以下信息的格式化字符串:
- 调度器当前状态(步数、队列长度)
- 每个任务的详细信息(优先级、下次执行步数、类型)
- 每个任务内部的上下文信息(缩进显示)
§输出格式
-> AsyncScheduler Status:
- Current Step: 42
- Total Tasks in Queue: 3
--- Task Queue Details ---
[Task #0] Priority: 1 (Next run at step 45), Type: SomeRunnable
... (task internal context)
[Task #1] Priority: 0 (Next run at step 43), Type: AnotherRunnable
... (task internal context)
Auto Trait Implementations§
impl Freeze for AsyncScheduler
impl !RefUnwindSafe for AsyncScheduler
impl Send for AsyncScheduler
impl Sync for AsyncScheduler
impl Unpin for AsyncScheduler
impl !UnwindSafe for AsyncScheduler
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
Mutably borrows from an owned value. Read more