You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Process any pending messages in the internal queue, calling wrapped actor's `handle()`.fnprocess_queue(&mutself,context:&mut <SelfasActor>::Context) -> Result<(),A::Error>{// Handle all messages that should have been handled by now.let now = Instant::now();whileself.queue.peek().map(|m| m.fire_at <= now).unwrap_or(false){let item = self.queue.pop().expect("heap is non-empty, we have just peeked");let message = match item.payload{Payload::Delayed{ message } => message,Payload::Recurring{mut factory, interval } => {let message = factory();self.queue.push(QueueItem{fire_at: item.fire_at + interval,payload:Payload::Recurring{ factory, interval },});
message
},};// Let inner actor do its job.//// Alternatively, we could send an `Instant` message to ourselves.// - The advantage would be that it would go into the queue with proper priority. But it// is unclear what should be handled first: normal-priority message that should have// been processed a while ago, or a high-priority message that was delivered now.// - Disadvantage is we could easily overflow the queue if many messages fire at once.self.inner.handle(&mutTimedContext::from_context(context), message)?;}Ok(())}
Combined with the fact that we call this from handle().
It was introduced in Fix timed messages for busy actors #73 which fixed a converse issue: we need to make sure we don't reintroduce it. It has an unit test fortunately.
I think that we should:
send message to ourselves instead of calling inner.handle(), so that it goes through the actor loop and gets proper priority
only process one message at a time: change while let to if let
this would resolve the concern in the TODO in the code that we
…when due
Also rename `fire_at` to `enqueue_at` to be explicit about the fact.
This is a trade-off that prevents 2 sorts of bad behavior:
- actors with send-sending messages never handling any delayed/recurring messages (#72)
- actors with recurring messages that are slower to handle than their interval eventually not processing any outside messages (#79)
See the tweaked tests for the change of behavior.
Caused by this code
Combined with the fact that we call this from
handle()
.I think that we should:
inner.handle()
, so that it goes through the actor loop and gets proper prioritywhile let
toif let
CC @goodhoko.
The text was updated successfully, but these errors were encountered: