Skip to content

Commit

Permalink
Make job queue take all jobs on iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Feb 7, 2023
1 parent 05c8816 commit 0cf6662
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions boa_examples/src/bin/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a> JobQueue for Queue<'a> {

let jqueue = async {
loop {
let Some(job) = self.jobs.borrow_mut().pop_front() else {
if self.jobs.borrow().is_empty() {
finished.set(finished.get() | 0b10);
if finished.get() == 0b11 {
// All possible futures and jobs were completed. Exit.
Expand All @@ -94,10 +94,13 @@ impl<'a> JobQueue for Queue<'a> {
};
finished.set(finished.get() & 0b01);

if let Err(e) = job.call(&mut context.borrow_mut()) {
eprintln!("Uncaught {e}");
let jobs = std::mem::take(&mut *self.jobs.borrow_mut());
for job in jobs {
if let Err(e) = job.call(&mut context.borrow_mut()) {
eprintln!("Uncaught {e}");
}
future::yield_now().await;
}
future::yield_now().await;
}
};

Expand Down

0 comments on commit 0cf6662

Please sign in to comment.