Skip to content

Commit

Permalink
Send Idle message to actors when they are idle. (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored Dec 5, 2018
1 parent 56c1ee9 commit 7c8bf1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions neo/IO/Actors/Idle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Neo.IO.Actors
{
internal sealed class Idle
{
public static Idle Instance { get; } = new Idle();
}
}
8 changes: 6 additions & 2 deletions neo/IO/Actors/PriorityMessageQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public void Enqueue(IActorRef receiver, Envelope envelope)

public bool TryDequeue(out Envelope envelope)
{
if (high.TryDequeue(out envelope)) return true;
if (low.TryDequeue(out envelope)) return true;
if (high.TryDequeue(out envelope) || low.TryDequeue(out envelope))
{
if (Count == 0 && !(envelope.Message is Idle))
low.Enqueue(new Envelope(Idle.Instance, ActorRefs.NoSender));
return true;
}
return false;
}
}
Expand Down

0 comments on commit 7c8bf1f

Please sign in to comment.