1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-11-23 19:42:51 +01:00
Minecraft-Phantom-Panel/Utils/Phantom.Utils.Actor/Mailbox/UnboundedJumpAheadMessageQueue.cs

25 lines
750 B
C#

using Akka.Actor;
using Akka.Dispatch.MessageQueues;
namespace Phantom.Utils.Actor.Mailbox;
sealed class UnboundedJumpAheadMessageQueue : BlockingMessageQueue {
private readonly Queue<Envelope> highPriorityQueue = new ();
private readonly Queue<Envelope> lowPriorityQueue = new ();
protected override int LockedCount => highPriorityQueue.Count + lowPriorityQueue.Count;
protected override void LockedEnqueue(Envelope envelope) {
if (envelope.Message is IJumpAhead) {
highPriorityQueue.Enqueue(envelope);
}
else {
lowPriorityQueue.Enqueue(envelope);
}
}
protected override bool LockedTryDequeue(out Envelope envelope) {
return highPriorityQueue.TryDequeue(out envelope) || lowPriorityQueue.TryDequeue(out envelope);
}
}