Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMurray committed Jul 2, 2023
1 parent 5aa5573 commit 36889b4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/executor/thread_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ impl Executor for ThreadExecutor {
}
// Iterate over the actor-cells and check if there are any non-empty mailboxes.
// If one is found, process a message from it.
let mut messages_processed = 0;
for (_, cell) in self.actor_cells.iter_mut() {
if !cell.is_shutdown() {
// TODO: Forward messages to dead-letter-queue
continue;
}
if !cell.mailbox.is_empty() {
messages_processed += 1;
let result = cell.mailbox.try_recv();
if let Ok(letter) = result {
trace!("[{}] processing message: {:?}", &cell.address, &letter);
Expand All @@ -125,8 +127,12 @@ impl Executor for ThreadExecutor {
}
}
}
trace!("nothing to do, sleeping...");
thread::sleep(Duration::from_millis(SLEEP_DURATION_MS));

// If no messages were processed, sleep for a bit to avoid busy-waiting
if messages_processed == 0 {
trace!("nothing to do, sleeping...");
thread::sleep(Duration::from_millis(SLEEP_DURATION_MS));
}
}

self.runtime_manager.notify_shutdown(self.name);
Expand Down

0 comments on commit 36889b4

Please sign in to comment.