Skip to content

Commit

Permalink
Send Idle message to actors when they are idle.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Dec 5, 2018
1 parent 56c1ee9 commit 6f8189a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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();
}
}
7 changes: 6 additions & 1 deletion neo/IO/Actors/PriorityMessageQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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 (low.TryDequeue(out envelope))
{
if (low.Count == 0 && !(envelope.Message is Idle))
low.Enqueue(new Envelope(Idle.Instance, ActorRefs.NoSender));
return true;
}
return false;
}
}
Expand Down

0 comments on commit 6f8189a

Please sign in to comment.