示例#1
0
            async Task CheckClientRef(Func <IClientObservable, object> buildMessage)
            {
                var actor = system.FreshActorOf <ITestActor>();

                using (var observable = await system.CreateObservable())
                {
                    await actor.Tell(buildMessage(observable));

                    Notification @event = null;

                    var done         = new AutoResetEvent(false);
                    var subscription = observable.Subscribe((Notification e) =>
                    {
                        @event = e;
                        done.Set();
                    });

                    await actor.Tell(new Publish { Text = "c-a" });

                    done.WaitOne(TimeSpan.FromMilliseconds(100));
                    Assert.That(@event.Text, Is.EqualTo("c-a"));

                    subscription.Dispose();
                    await actor.Tell(new Publish { Text = "kaboom" });

                    done.WaitOne(TimeSpan.FromMilliseconds(100));
                    Assert.That(@event.Text, Is.EqualTo("c-a"));
                }
            }
示例#2
0
            public async void Client_to_actor()
            {
                var actor = system.FreshActorOf <TestActor>();

                using (var observable = await system.CreateObservable())
                {
                    await actor.Tell(new Attach { Observer = observable.Ref });

                    Notification @event = null;

                    var done         = new AutoResetEvent(false);
                    var subscription = observable.Subscribe((Notification e) =>
                    {
                        @event = e;
                        done.Set();
                    });

                    await actor.Tell(new Publish { Text = "c-a" });

                    done.WaitOne(TimeSpan.FromMilliseconds(100));
                    Assert.That(@event.Text, Is.EqualTo("c-a"));

                    subscription.Dispose();
                    await actor.Tell(new Publish { Text = "kaboom" });

                    done.WaitOne(TimeSpan.FromMilliseconds(100));
                    Assert.That(@event.Text, Is.EqualTo("c-a"));
                }
            }
示例#3
0
        public async Task Join()
        {
            notifications = await system.CreateObservable();

            notifications.Subscribe((ChatRoomMessage msg) =>
            {
                if (msg.User != user)
                {
                    Console.WriteLine(msg.Text);
                }
            });

            await room.Tell(new Join { User = user, Client = notifications.Ref });
        }
示例#4
0
        static async Task Run(IClientActorSystem system)
        {
            var some    = system.ActorOf <ISomeActor>("some");
            var another = system.ActorOf <IAnotherActor>("another");

            var actor = await some.Ask(new GetSelf());

            var stream = await some.Ask(new GetStream());

            var item1 = new Item {
                Name = "PS3", Paid = DateTimeOffset.UtcNow.AddHours(-2), Price = 600
            };
            var item2 = new Item {
                Name = "XBOX", Paid = DateTimeOffset.UtcNow.AddHours(-9), Price = 500
            };

            await another.Tell(new Notify { Observer = actor, Item = item1 });

            await another.Tell(new Push { Stream = stream, Item = item2 });

            var received = await some.Ask(new GetReceived());

            Verify(received[0], item1);
            Verify(received[1], item2);

            using (var observable = await system.CreateObservable())
            {
                Item observed = null;
                using (observable.Subscribe <Item>(x => observed = x))
                {
                    var item3 = new Item {
                        Name = "Nintendo", Paid = DateTimeOffset.UtcNow, Price = 300
                    };
                    await another.Tell(new Notify { Observer = observable.Ref, Item = item3 });

                    Thread.Sleep(2000);
                    Verify(observed, item3);
                }
            }
        }