Skip to content

Instantly share code, notes, and snippets.

@ronnieoverby
Last active September 23, 2016 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronnieoverby/fc5329c0131fe6b942ac7027739d76f0 to your computer and use it in GitHub Desktop.
Save ronnieoverby/fc5329c0131fe6b942ac7027739d76f0 to your computer and use it in GitHub Desktop.
void Main()
{
using (var actsys = ActorSystem.Create("as1"))
{
var a1 = actsys.ActorOf(Props.Create(() => new Dumper()),"a1");
var r1 = actsys.ActorOf(Props.Empty.WithRouter(new BroadcastGroup(a1.Path.ToString())),"r1");
var w1 = actsys.ActorOf(Props.Create(() => new Watcher(a1,r1)),"w1");
for (int i = 0; i < 3; i++)
{
r1.Tell("good msg");
Thread.Sleep(333);
}
r1.Tell(PoisonPill.Instance);
// please ignore the fact that I'm using Thread.Sleep for sync purposes
// in this simple test. I realize it's not a good idea in general.
Thread.Sleep(333);
for (int i = 0; i < 300; i++)
{
r1.Tell("should be a dead msg, but if you see this. it was delivered.");
Thread.Sleep(333);
}
actsys.Terminate().Wait();
}
}
class Dumper : ReceiveActor
{
public Dumper()
{
ReceiveAny(x =>
{
x.Dump();
});
}
}
class Watcher : ReceiveActor
{
public Watcher(params IActorRef[] refs)
{
Receive<Terminated>(x =>
{
x.ActorRef.Path.ToString().Dump("terminated");
});
foreach (var a in refs)
{
Context.Watch(a);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment