-
-
Save ronnieoverby/fc5329c0131fe6b942ac7027739d76f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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