feat: park idle task refresh and bound delivery to one callback per turn
This commit is contained in:
+6
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user