Exemplo n.º 1
0
        private static dynamic WaitForResponse(ReplaySubject <dynamic> s, Message message)
        {
            var result = s
                         .FirstAsync(x => x["message-id"] == message.MessageId)
                         .Timeout(TimeSpan.FromSeconds(5))
                         .Wait();

            return(result);
        }
        public async Task EmitPointerStateWhenUpdated()
        {
            var points = new ReplaySubject<PointerState>();
            var observer = new PointerObserver(points);

            observer.Update(new GameTime(), Point.Zero);
            Assert.AreEqual(new PointerState { Position = new GeoPoint() }, await points.FirstAsync());

            observer.Update(new GameTime(), new Point(Config.SpriteSize, Config.SpriteSize));
            Assert.AreEqual(new PointerState { Position = new GeoPoint { X = 1, Y = 1 } }, await points.Skip(1).FirstAsync());
        }
Exemplo n.º 3
0
        private async Task editTimes(EditViewTapSource tapSource)
        {
            analyticsService.EditViewTapped.Track(tapSource);

            var isDurationInitiallyFocused = tapSource == EditViewTapSource.Duration;

            var duration = await durationSubject.FirstAsync();

            var startTime         = startTimeSubject.Value;
            var currentDuration   = DurationParameter.WithStartAndDuration(startTime, duration);
            var editDurationParam = new EditDurationParameters(currentDuration, false, isDurationInitiallyFocused);

            var selectedDuration = await Navigate <EditDurationViewModel, EditDurationParameters, DurationParameter>(editDurationParam)
                                   .ConfigureAwait(false);

            startTimeSubject.OnNext(selectedDuration.Start);
            if (selectedDuration.Duration.HasValue)
            {
                durationSubject.OnNext(selectedDuration.Duration);
            }
        }
Exemplo n.º 4
0
        static void MainA(string[] args)
        {
            var values = Observable.Range(1, 5);

            values.Inspect("values");
            values.Count().Inspect("count");

            var intSubj = new Subject <int>();

            intSubj.Inspect("intSubj");
            intSubj.Min().Inspect("min");     // not a running minimum!
            intSubj.Sum().Inspect("sum");     // requires all values
            intSubj.Average().Inspect("avg"); // double!

            intSubj.OnNext(2);
            intSubj.OnNext(4);
            intSubj.OnNext(1);
            intSubj.OnCompleted();

            // first, last, single
            var replay = new ReplaySubject <int>();

            // later
            replay.OnNext(-1); // doesn't complete unless OnCompleted
            replay.OnNext(2);

            replay.OnCompleted();

            replay.FirstAsync(i => i > 0).Inspect("FirstAsync"); // doesn't require completion

            replay.FirstOrDefaultAsync(i => i > 10)              // yields 0 because no element matches
            .Inspect("FirstOrDefaultAsync");                     // doesn't require completion

            replay.SingleAsync().Inspect("SingleAsync");         // try commenting out one of OnNext
            // requires completion! try commenting out OnCompleted -> no output

            //replay.SingleOrDefaultAsync()

            // Sum is always the final value, how about a running sum?
            var subj  = new Subject <double>();
            int power = 1;

            subj.Aggregate(0.0, (p, c) => p + Math.Pow(c, power++)).Inspect("poly");
            subj.OnNext(1, 2, 4).OnCompleted(); // 1^1 + 2^2 + 4^3

            // running sum? no problem
            var subj2 = new Subject <double>();

            subj2.Scan(0.0, (p, c) => p + c).Inspect("scan"); // same as Aggregate().TakeLast()
            subj2.OnNext(1, 2, 3);                            //.OnCompleted();
                                                              // OnCompleted doesn't really matter anymore
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            var values = Observable.Range(1, 5);

            values.Inspect("Values");
            values.Count().Inspect("Count");
            values.Average().Inspect("Average");
            values.Max().Inspect("Max");
            values.Min().Inspect("Min");
            values.Sum().Inspect("Sum");

            var replay = new ReplaySubject <int>();

            replay.OnNext(-1, 2);
            replay.OnCompleted();

            replay.FirstAsync(i => i > 0).Inspect("First Async");

            var replay2 = new ReplaySubject <int>();

            replay2.OnNext(-1);
            replay2.OnCompleted();

            replay2.FirstOrDefaultAsync(i => i > 0).Inspect("First Or Default Async");

            var replay3 = new ReplaySubject <int>();

            replay3.OnNext(-1);
            replay3.OnCompleted();

            replay3.SingleAsync().Inspect("Single Async");

            var replay4 = new ReplaySubject <int>();

            replay4.OnNext(-1, 2);
            replay4.OnCompleted();

            replay4.SingleOrDefaultAsync().Inspect("Single Or Default Async");

            var subj  = new Subject <double>();
            int power = 1;

            subj.Aggregate(0.0, (p, c) => p + Math.Pow(c, power++)).Inspect("Poly");
            subj.OnNext(1, 2, 4);
            subj.OnCompleted();

            var subj2 = new Subject <double>();

            subj2.Scan(0.0, (p, c) => p + c).Inspect("Scan");
            subj2.OnNext(1, 2, 3);
        }
        public async Task EmitPointerStateWhenUpdated()
        {
            var points   = new ReplaySubject <PointerState>();
            var observer = new PointerObserver(points);

            observer.Update(new GameTime(), Point.Zero);
            Assert.AreEqual(new PointerState {
                Position = new GeoPoint()
            }, await points.FirstAsync());

            observer.Update(new GameTime(), new Point(Config.SpriteSize, Config.SpriteSize));
            Assert.AreEqual(new PointerState {
                Position = new GeoPoint {
                    X = 1, Y = 1
                }
            }, await points.Skip(1).FirstAsync());
        }
        public async Task CanPublishAndReceiveOnChannel()
        {
            var expected = "CanPublishAndReceiveOnChannel";

            using (var socketConnection = new SocketConnection(TestsSetup.Host, TestsSetup.Port, Scheduler.Immediate))
            {
                using (var publisherConnection = new SocketConnection(TestsSetup.Host, TestsSetup.Port, Scheduler.Immediate))
                {
                    var subscriber = socketConnection.AsSubscriber();
                    var publisher = publisherConnection.AsPublisher();

                    var messagesChannel = await subscriber.Subscribe("channel1");
                    var replaySubject = new ReplaySubject<string>();
                    messagesChannel.Take(1).Select(x => x.Content).Subscribe(replaySubject);

                    await publisher.PublishMessage("channel1", expected);
                    var result = await replaySubject.FirstAsync();

                    Assert.AreEqual(expected, result); 
                }
            }
        }