feat: park idle task refresh and bound delivery to one callback per turn

This commit is contained in:
2026-10-23 01:50:56 +08:00
parent 5a1cf9d702
commit bd5c91ba99
6 changed files with 58 additions and 12 deletions
+6 -2
View File
@@ -399,7 +399,8 @@ pub struct Scheduler {
impl Scheduler {
/// Mutation boundaries collect unreachable owner/callback cycles before
/// this weak lookup. Idle timer polling does not rescan the entire heap.
pub fn poll(&self, vm: &mut Vm) -> Result<usize> {
pub fn poll(&self, vm: &mut Vm, limit: usize) -> Result<usize> {
anyhow::ensure!((1..=MAX_READY).contains(&limit), "invalid task poll limit");
let snapshot = self
.index
.lock()
@@ -408,6 +409,9 @@ impl Scheduler {
let now = Instant::now();
let mut work = 0;
for weak in snapshot {
if work >= limit {
break;
}
let Some(reference) = vm.upgrade(weak)? else {
continue;
};
@@ -428,7 +432,7 @@ impl Scheduler {
work += 1;
return finish(vm, reference, State::Cancelled);
}
if task.due > now || work >= MAX_READY {
if task.due > now {
return Ok(());
}
work += 1;